Skip to content

Instantly share code, notes, and snippets.

@cpuguy83
Created July 31, 2023 22:51
Show Gist options
  • Save cpuguy83/33794a58b933ee230f3307595790f56d to your computer and use it in GitHub Desktop.
Save cpuguy83/33794a58b933ee230f3307595790f56d to your computer and use it in GitHub Desktop.
Debugging stuff
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