1、条件测试结构
1) if/then结构:
判断命令列表的退出码是否为0,0为成功。
如果if和then在条件判断的同一行上的话, 必须使用分号来结束if表达式;
if和then都是关键字。
关键字(或者命令)如果作为表达式的开头, 并且如果想在同一行上再写一个新的表达式的话, 那么必须使用分号来结束上一句表达式。
if [ condition1 ]
then command1
command2
command3
elif [ condition2 ]
then command4
command5
else default-command
fiif/then结构可以包含嵌套的比较操作和条件判断操作:
if echo "Next *if* is part of the comparison for the first *if*."
if [[ $comparison = "integer" ]]
then (( a < b ))
else
[[ $a < $b ]]
fi
then echo '$a is less than $b'
fi