Created
July 31, 2023 22:51
-
-
Save cpuguy83/33794a58b933ee230f3307595790f56d to your computer and use it in GitHub Desktop.
Debugging stuff
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
set -e | |
prev_cmd="" | |
this_cmd="" | |
prev_line="" | |
this_line="" | |
debug_trap() { | |
prev_cmd="${this_cmd}" | |
this_cmd="${BASH_COMMAND}" | |
prev_line="${this_line}" | |
this_line="${BASH_LINENO[0]}" | |
} | |
trap 'debug_trap' DEBUG | |
report_errors() { | |
ec=$? | |
if [ ${ec} -ne 0 ]; then | |
echo ${BASH_SOURCE[0]}:${prev_line} ${prev_cmd} >&2 | |
fi | |
} | |
trap 'report_errors' EXIT | |
echo do some stuff | |
false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment