I. The existence and judgment of documents
-D to determine if the file exists and whether it is a directory file (the directory is true)
-E to determine if the file exists (exists as true)
-F to determine if the file exists and is a normal file (the normal file is true)
Second, the file permission to judge
-R to determine if the file exists and whether it has Read permission (Read permission is true)
-W to determine if the file exists and has Write permission (Write permission is true)
-X determines whether the file exists and has execute permission (with Execute permission true)
Third, integer judgment
The shell is a weakly typed language, and all of the default contents are strings, but the following comparison commands automatically convert the contents of both sides to numeric types, so no (())
-eq equal
-ne Not Equal
-ge greater than or equal to
-le less than or equal to
-GT Greater than
-lt less than
Iv. type of string
-Z string is empty, NULL returns True
-n string is not NULL, non-null return True
= = equals, equality is true (= can also be used to determine whether a string is equal, but is easily confused with assignment operations)
! = range, not equal to True
V. Multiple conditions of judgment
A is really true
-O One true is True
! Non -
VI. If statement
Single branch:
If [conditional judgment]
Then program
Fi
Dual Branch:
If[]
Then
echo "1"
Else
echo "2"
Fi
Multi-branch:
If[]
Then
echo "1"
Elif[]
Then
echo "2"
Else
echo "3"
Fi
Vii. Case Statements
Case $a in
"Yes")
echo "AA"
;;
"No")
echo "BB"
;;
*)
echo "CC"
;;
Esac
Viii. for Loop
For I in 1 2 3 4 5
Do
Echo $i
Done
For I in $ (cat a.txt)
Do
Echo $i
Done
S=0
For ((i=1;i<=100;i=i+1))
Do
s=$ (($s +$2))
Done
Nine, while loop
While [$i-le 100]
Do
.....
Done
While Read line
Do
......
Done < cat A.txt
Shell Process Control Statements