First, preface
In structured programming, there are three main structures: sequential, branching, and cyclic. This shows the importance of branch judgment.
And in shell programming often encountered in the case of judgment, such as: Determine whether the file exists, the directory exists, and so on.
II. structure of the IF statement
if conditions Then ... elif conditions ... Else ... fi
Iii. branch judgment in the shell
There are several judgments in the shell:
1. String judgments
STR1 =! = str2 When two strings of content are not true at the same time -n str1 when the length of the string is greater than 0 is true -z str1 when the string length is 0 is true str1 when the string is not empty is true
2. Digital Judgment
N1------le n2 N1 less than equals N2 is true
3. Document Judgment
file The file can be read as true -w file file can be written as a true file for real files executable as normal file files for a directory file as true file file for characters special files as true for block special files for true file The file file is true for the linked file when the device specified by the descriptor is terminal
4. Combination
-A and -o or ! Non -
The IF statement for the shell script