Created
October 23, 2015 14:02
-
-
Save netmute/006394a16c07c9b986a5 to your computer and use it in GitHub Desktop.
bash error handler
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
#!/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