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
Note also, each command's exit status is stored in the shell variable $?, which you can check immediately after running the command. A non-zero status indicates failure:
my_command if [ $? -eq 0 ] then echo "it worked" else echo "it failed" fi