Skip to content

Instantly share code, notes, and snippets.

@pjvandehaar
Created January 29, 2016 17:45
Show Gist options
  • Save pjvandehaar/a84aa1e2a9be5fb5b911 to your computer and use it in GitHub Desktop.
Save pjvandehaar/a84aa1e2a9be5fb5b911 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -euo pipefail
error() {
local parent_lineno="$1"
local message="$2"
local code="${3:-1}"
if [[ -n "$message" ]] ; then
echo "Error on or near line ${parent_lineno}: ${message}; exiting with status ${code}"
else
echo "Error on or near line ${parent_lineno}; exiting with status ${code}"
fi
touch FAILED
exit "${code}"
}
trap 'error ${LINENO}' ERR
echo hi
eco woot
echo wat
touch SUCCEEDED
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment