First, learn Zhao Wenyu's summary script:
1. Variables
host=$ (/bin/hostname)
Assigns the result of the command executed in () to the host variable
Host= '/bin/hostname '
Assigns the execution result inside the anti-quotation mark to the host variable
2.echo
echo $? Successful or unsuccessful execution of the last command? is 0
3.if and other statements that require conditional judgment
(1) determine if the file exists and whether it is a file
[-F file]
To determine if a file exists and is a writable file
[-W file]
Determine if a file exists and is an executable file
[-X file]
Determine if a file exists and is a readable file
[-R File]
Determine if a file exists and is a directory file
[-D file]
To determine if a file exists and is an empty file
[-S file]
Determine if a file exists
[-E File]
[] and test function as-A and-O (and, or)
(2) integer value comparison judgment
[-eq]
["$a" = "0"]
((a% 2 = = 0))
Note: ((a = = 50)) The comparison of values, in (()) in the use of No $ are the same
[-N string]//string longer than 0
[-Z string] The length of the//string is 0
String1=string2//String equality
STRING1!=STRING2//strings are not equal
[INT1-GT Int2]//int1>int2 greater than
[Int1-ge Int2]//int1>=int2 greater equal
[Int1-eq Int2]//int1=int2 equal
[Int1-ne Int2]//int1!=int2 not Equal
[Int1-le Int2]//int1<=int2 less equal
[Int1-lt Int2]//int1<int2 less than
(3) character string comparison
["$a" = "$b"]
[-N "$a"] and ["$a"] determine whether the string $ A is empty
[["$a" = = * "Redhat" *]] and [["$a" = * "Redhat" *]] determine-whether a $ A contains a redhat string
(4)if followed by command && and | |
If rpm-q gcc && ID tom| | echo "SSS"//&& if the previous command executes successfully then execute && after the command is executed otherwise | | The following command
4.sed
Sed-ri/^ #ServerName. *:80$/s/^#///etc/selinux/config//Find the line with/etc/seliunx/config beginning with: 80 in #servername file and replace # with blank
5.
Df-th|grep "/$" |awk ' {print $6} ' |sed ' s/%//'//df after intercepting a field and substituting
6.
Self-paced shell scripts