#if Else statement, divided into three kinds: if...fi; If ... else ... fi; If ... elif...else...fi
#if Else FI statement syntax
#if [Expression]
#then
# Statement to being executed if expression is true
#else
# Statement to being executed if expression is not true
#fi
#if elif Else FI statement syntax: Which statement executes if the expression is true, and if all false executes the Else statement
#if [Expression 1]
#then
# Statement (s) to BES executed if expression 1 is true
#elif [Expression 2]
#then
# Statement (s) to BES executed if expression 2 is true
#elif [Expression 3]
#then
# Statement (s) to BES executed if expression 3 is true
#else
# Statement (s) to BES executed if no expression is true
#fi
1 a=30
2 b=20
3 if [ $a == $b ]
4 then
5 echo "a is equal to b"
6 elif [ $a -gt $b ]
7 then
8 echo "a is greater than b"
9 elif [ $a -lt $b ]
10 then
11 echo "a is less than b"
12 else
13 echo "None of the condition met"
14 fi
The #if else statement can also be written as a line and run as a command, as follows:
1 if 2*31+5 ]; Then Echo " true " fi
##if else statements are often used in conjunction with the test command
#test command is used to check if a certain condition is true, similar to []
1 num1=$[2*3]
2 num2=$[1+5]
3 if test ${num1} -eq ${num2}
4 then
5 echo ‘The two numbers are equal!‘
6 else
7 echo ‘The two numbers are not equal!‘
8 fi
Linux Gvim Shell If...else statement