Skip to content

Instantly share code, notes, and snippets.

@ViktorStiskala
Created June 29, 2015 11:19
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 ViktorStiskala/b958af63e9e8fef2948d to your computer and use it in GitHub Desktop.
Save ViktorStiskala/b958af63e9e8fef2948d to your computer and use it in GitHub Desktop.
Bash catch exception
#!/bin/bash
set -e
err_report() {
ERR=$?
echo "$1 failed on line $2 ('$3') with error code $ERR" 1>&2
exit $ERR
}
trap 'err_report "$BASH_SOURCE" "$LINENO" "$BASH_COMMAND"' ERR
echo "l" | grep f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment