I am writing a bash script to automate the build process. There are two major build blocks, one is an ant task and one is a plain old mvn clean install. I want
There's a command built-in to bash which performs exactly this.
# exit when any command fails
set -e
I put this at the top of my bash scripts, which I copied from this excellent resource.
# keep track of the last executed command
trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG
# echo an error message before exiting
trap 'echo "\"${last_command}\" command filed with exit code $?."' EXIT