问题:
I am a noob in shell-scripting.我是 shell 脚本的菜鸟。 I want to print a message and exit my script if a command fails.如果命令失败,我想打印一条消息并退出我的脚本。 I've tried:我试过了:
my_command && (echo 'my_command failed; exit)
but it does not work.但它不起作用。 It keeps executing the instructions following this line in the script.它继续执行脚本中这一行后面的指令。 I'm using Ubuntu and bash.我正在使用 Ubuntu 和 bash。
解决方案:
参考一: https://en.stackoom.com/question/G2RB参考二: https://stackoom.com/question/G2RB