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
If you want that behavior for all commands in your script, just add
set -e set -o pipefail
at the beginning of the script. This pair of options tell the bash interpreter to exit whenever a command returns with a non-zero exit code.
This does not allow you to print an exit message, though.