I am a noob in shell-scripting. I want to print a message and exit my script if a command fails. I\'ve tried:
my_command && (echo \'my_command failed
You can also use, if you want to preserve exit error status, and have a readable file with one command per line:
my_command1 || exit $? my_command2 || exit $?
This, however will not print any additional error message. But in some cases, the error will be printed by the failed command anyway.