問題:
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