I. Condition statements
1,
If [expression]
Then
# Code block
Fi
2,
If [expression]
Then
# Code block
Else
# Code block
Fi
3,
If [expression]
Then
# Code block
Else if [expression] # Replace this field with Elif [expression]
Then
# Code block
Else
# Code block
Fi
Fi
Ii. Comparison of common condition statements
Comparison operation Integer Operation string operation
Same-eq =
Different-ne! =
Greater than-GT>
Less than-lt <
Less than or equal to-le
Greater than or equal to-Ge
Blank-z
Not empty-n
-E: determines whether the file already exists.
-F files are common files.
-S file size is not zero
-D file is a directory
-The R file can be read by the current user.
-W files can be written to the current user
-The X file can be executed on the current user.
For example:
#! /Bin/sh
Folder =/home
[-R "$ folder"] & Echo "can read $ folder" # "&" indicates that when the preceding is true, the following command is executed. It means "that.
[-F "$ folder"] | echo "this is not file" # "|" indicates that when the preceding value is false, the following command is executed. It means "otherwise.