Created
August 25, 2019 02:28
-
-
Save urjitbhatia/15e1a9457de290c64e3f3b5e3229ace6 to your computer and use it in GitHub Desktop.
Bash debug trick
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# exit when any command fails | |
set -e | |
current_command=$BASH_COMMAND | |
last_command="" | |
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment