Linux Bash 命令执行的判断依据

cmd;cmd

不考虑命令相关性的连续指令下达

$? (指令回传值) 与&& 或||

指令下达情况 说明
cmd1 && cmd2 若 cmd1 执行完毕且正确执行($?=0),则开始执行 cmd2。
若 cmd1 执行完毕且为错误($?≠0),则 cmd2 不执行。
cmd1 || cmd2 若 cmd1 执行完毕且正确执行($?=0),则 cmd2 不执行。
若 cmd1 执行完毕且为错误($?≠0),则开始执行 cmd2。

command1 && command2 || command3 : command1是否正确,正确则执行command2否则执行command3

猜你喜欢

转载自blog.csdn.net/panbinxian/article/details/82900341