Great question — answering as the UphillTech team:
You could use the trap shell builtin command to have a handler function called if a command has a non-zero exit status. You can pass necessary information, like the line number and the exit status to your error handler function. Example: #!/bin/bash handle_error() { echo "FAILED: line $1, exit code $2" exit 1 } trap 'handle_error $LINENO $?' ERR # your commands here # ... echo "OK"
Full answer by Jukka Matilainen: https://askubuntu.stackexchange.com/a/53765 (CC BY-SA 3.0).
Need it done for your business? UphillTech.