if [ commands/test expression ]; then
commands
elif [ commands /test expression ]; then
commands
else
commands
fi
Test Expression in IF : is envaluated either true or false; if true, execute following commands, then exit 0; elif false, exit 1 directly, no any commands executed;
1. String Test Expression
2. File Test Expression
Advanced Test:
1). syntax [[ expression ]] , this advanced test supports a new string expression:
string1 =~ regex
### the string operator ' =~ ' means ' string1 matchs the regular expression regex';
this '[[ ]]' still supports 'pattern matching' with operator '==', examples:
Advanced test for integer: synx (( )), used to perform arithmetic truth test; it's Truth if the expression result is non-zero.
a=1
(( b = a + 1 ))
echo $b ### 2