Skip to content

Instantly share code, notes, and snippets.

@urjitbhatia
Created August 25, 2019 02:28
Show Gist options
  • Save urjitbhatia/15e1a9457de290c64e3f3b5e3229ace6 to your computer and use it in GitHub Desktop.
Save urjitbhatia/15e1a9457de290c64e3f3b5e3229ace6 to your computer and use it in GitHub Desktop.
Bash debug trick
#!/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