One, branch control statements
1. If: Fi condition
if condition; Then
Action
Fi
2. If: else.. Fi condition
If Condition;then
Action
Else
Action
Fi
3. If: else if: else.. Fi condition
If Condition;then
Action
else if Condition;then
Action
Else
Action
Fi
Note: If and SLSE statements can be nested, and if condition judgments can become very long, you can use logical operators to make him a little more concise:
[Condition] && action; #如果condition条件为真, the action is executed;
[Condition] | | Action #如果condition条件为假, the action is executed;
Second, circular control statements
1. For loop
for var in list;
Do
Action
Done
Where list can be a string, a sequence, or an array.
For loop statements in C language:
For ((i=0;i<10;i++))
{
Action
}
Or
For ((i=0;i<10;i++));
Do
Action
Done
2. While loop
While condition
Do
Action
Done
3. Until cycle syntax
Until condition
Do
Action
Done
Second, logical and logical expressions
1. Common logical operators are as follows:
L && (or-a): Logic and
L | | (Or-O): logical OR
2. Logical expression
1) Arithmetic comparison: Conditions are generally placed in the [], remember that the brackets before and after the need to leave a space.
Common arithmetic operators:
L-eq: Equals
L-ne: Not equal to
L-GT: Greater Than
L-LT: Less than
L-ge: greater than or equal to
L-le: Less than or equal to
2) file System Runner: Conditional comparison is generally placed in the [], remember that the brackets before and after the need to leave a space.
l [-F $file _var]: The given variable contains a normal file or filename and returns True.
l [-X $var]: The given file contains executable permissions and returns TRUE.
l [-D $var]: The given variable contains a directory and returns TRUE.
l [-E $var]: The given variable contains a file that exists and returns true.
l [-C $var]: The given variable contains a character device path and returns True.
l [-B $var]: The given variable is a block device file path that returns TRUE.
l [-W $var]: The given file contains writable permissions and returns TRUE.
l [-R $var]: The given file contains the readable permission, returns True.
l [-L $var]: The given file contains a symbolic link that returns TRUE.
3) string comparison: The condition comparison is generally placed in double [], remember that before and after the brackets need to leave a space.
-Z: String is an empty string and returns True.
-N: String is a non-empty string and returns True.
4) The test command is used to perform conditional judgments, and the test command avoids excessive [].
For example:
If [$var-eq 0];then
echo "true"
Fi
Can be written as:
if test $var-eq 0;then
echo "true"
Fi
Process Control statements for shell scripts