Skip to content

Instantly share code, notes, and snippets.

@netmute
Created October 23, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save netmute/006394a16c07c9b986a5 to your computer and use it in GitHub Desktop.
Save netmute/006394a16c07c9b986a5 to your computer and use it in GitHub Desktop.
bash error handler
#!/usr/bin/env bash
set -e
error_handler() {
local lineno="$1"
local message="$2"
if [[ -n "$message" ]]; then
echo "error on line $lineno: $message"
else
echo "error on line $lineno"
fi
}
trap 'error_handler ${LINENO}' ERR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment