Overview: In Linux shell programming, there are many conditional expressions for comparison/judgment, and this article makes a brief summary of them.
1. String comparison! Take the anti-n str string STR is NOT NULL
-Z str string str is NULL
STR1 =
1. Use shell script get_file_stat.sh statistics The number of directories in the bin directory executable file number, text file number
#!/bin/bashCd/binDir= ' ls-l |grep "^d" | Wc-l 'Exefile= ' Find/bin-perm +111| Wc-l 'Txt_file= ' Find/bin-name "*
1. First, write a simple shell script
Vimtest.sh (Nano is not used to use VIM)
Enter Vim and press the I key, then enter (#!/bin/sh symbol #! to tell the system that its subsequent parameters are the program used to execute the file.) )
$: The name of the executing script $* and $@: Return all parameters to $#: The number of arguments $_: represents the last parameter of the previous command $$: The PID $! that represents the command that was last executed: The PID $?: A flag that
1. Analog Linnux Login Shell
#/bin/bashEcho-n "Login:"Read nameEcho-n "Password:"Read passwdif [$name = "CHT"-a $passwd = "abc"];thenecho "The host and password is right!"else echo "Input is error!"Fi
2. Compare the size of two
File expression-e filename true if filename exists-d filename If filename is a directory, true-F filename True if filename is a regular file-L filename True if filename is a symbolic link-r filename If filename is readable, true-W filename if
If the file is a. css file or a. js file, it is processed.file=$1if ["${file##*.}" x = "css" x]| | ["${file##*.}" x = "JS" x];then do somethingfiAttention:1> extract file suffix name: ${file##*.}# #是贪婪操作符, match from left to right, match to the
# Experimental Case One,**Writing sysmon.sh Scripts(1) Use the DF command to extract the disk occupancy of the root partition and assign a value to the variable dug.(2) Use the Mpstat command to extract the CPU usage (Install the SYSSTAT package)
1) Count the number of rows in the index.php file in the current directory[[email protected]_web1 ~]# cat index.php |wc -l172) Statistics web directory, JS file number:[[email protected]_web1 ~]# find web/ -name "*.js" |wc -l3) Statistics web
1. Shell ConceptThe shell is a program written in C, which is a bridge for users to use LinuxThe shell is both a command voice and a programming voiceA shell is an application that provides an interface through which users access the operating
Preface written using BASH Shell
ProgramThe for loop is often used, especially from 1 to 100. Here we record several types of loop method classes in shell from 1 to 100.
C Language
For (I = 1; I In usage
For I in {1 .. 100} doecho $ idone
SEQ
1. run commands in the background
Cron: System scheduling process. It can be used to run jobs during off-peak hours every day, or during different periods of one week or one month.At: Command. It is used to run some special jobs at a specific time,
I am studying Linux Shell script recently.Linux Shell scripting tutorial (LSST) v1.05r3But because it is in English, it is also a deep impression. Now, go to the topic.
1. How to Write shell script?
A. First, use any Compiler (Vi, Vim, kwrite,...)
I. Use of local variables
Local variables act only in this shell, just like local variables. It does not affect variables in other shells.
1. Show variable valuesYou can use the echo command. Note that you must add the $ symbol before the variable
Create a shell to parse the INI file and use it to parse the ini configuration file in the HA framework.
The tested INI file is one found in the system.
# Example driver definitions# Driver from the postgresql-odbc package# Setup from the unixODBC
Source: http://zhidao.baidu.com/question/322131711.html
File comparison operator-E filename if filename exists, it is true [-E/var/log/syslog]-D filename if filename is a directory, it is true [-D/tmp/mydir]-F filename if filename is a regular
If parameters in Shell in Linux[-A file] true if the file exists.[-B file] If the file exists and is a special block file, it is true.[-C file] If the file exists and is a special word file, it is true.[-D file] If the file exists and is a directory,
Preface The basic languages I have mastered: PhP (most familiar with, the code in the project is implemented using it), bash shell (O & M tool), and C (ACM dedicated ), it seems that only C can implement multithreading, but C is only used to learn
Notes for shell script programs: variables can be directly used without prior declaration; the variable does not have any data type. The default value is a string; no space is allowed on any side of the equal sign of the value assignment operation.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service