shell 流程控制之if判断
一 单分支
语法:
if 条件;then
要执行的命令1
要执行的命令2
要执行的命令3
...
fi
# 上述语法可以用一行代码代替
[ 条件信息 ] && xxx
# 注意:if 测试中还可以执行命令 根据命令的返回值做判断
二 双分支
语法:
if 条件;then
要执行的命令1
要执行的命令2
要执行的命令3
...
else
要执行的命令1
要执行的命令2
要执行的命令3
...
fi
# 上述语法可以用一行代码代替
[ 条件信息 ] && xxx || xxxx
三 多分支
语法:
if 条件;then
要执行的命令1
要执行的命令2
要执行的命令3
...
elif 条件;then
要执行的命令1
要执行的命令2
要执行的命令3
...
else
要执行的命令1
要执行的命令2
要执行的命令3
...
fi