①if-elif-elif-else-fi
If-fi
' if ($a >); then echo $a; fi ' or ' if [$a-gt];then echo $a; Fi '
If-else-fi
' if ($a =), then echo $a; else echo 30;fi ' or ' if [$a-eq];then echo $a; else echo 30;fi '
If-elif-elif-else-fi
' if ($a >) && (($a =)); then echo $a; elif (($a > 20)) | | ($a =); then echo $[$a +1];else echo ' Sorry '; Fi '
Note: If you enclose the condition in square brackets [], there must be a space between the if and the [,] operand and [,]
> * * * *-gt = * *-EQ >= * * *-ge <= * *-le < * * * * * *-LT
If Judge document properties
' If [-defrwx filename] '-D exists && directory-E exists-F exists && normal file-R readable-W writable-X Executable
②case $a in value1) command;; value2) command;; VALUE3) command;; *) command; Esac
' Read-p ' please input a number: ' A;
Case $[$a%2] in
0)
echo "The number is even!";;
1)
echo "The number is odd!";;
*)
echo "This is impossible!";;
Esac '
③for Cycle
For variable name in loop condition; do command[;] Done
eg
A= ' seq 1 10 ';
For i in $a;d o echo $i;d One or for i in ' seq 1 ';d o echo $i;d One or for I in 1 2 3 4 5;do echo $i;d One
Note: ' seq a b ' denotes a sequence from a to B, e.g. ' SEQ 1 10 ' generates a sequence from 1 to 10
④while Cycle
while condition; do Command;done
eg
a=10;
While [$a-ge 1];d o
echo $a;
A=$[$-1];
Done
Syntax knowledge of shell scripts--Process Control