if -then 语句shell
if -then 语句有以下格式bash
if commandcommand
then 脚本
commandsco
f i
bash shell 的if语句会先运行if后面的那个命令,若是改命令的退出状态码是0的话,位于then 部分的命令就会被执行,若是该命令的状态码是其余值的话。then部分的命令就不会被执行,bash shell 会继续执行脚本中的下一个命令,f i 语句表示if -then 语句到此结束
说明:if-then 语句还有另一种形式
if command ;then
commands
f i
if command
then
commands
else
commands
f i