Skip to content

Instantly share code, notes, and snippets.

@chawkinsuf
Created September 4, 2014 18:23
Show Gist options
  • Save chawkinsuf/4a65cc54b3337c7fcd95 to your computer and use it in GitHub Desktop.
Save chawkinsuf/4a65cc54b3337c7fcd95 to your computer and use it in GitHub Desktop.
Check for errors
check_error()
{
# Check for an error
if [ "${1}" -ne "0" ]; then
# Check for a custom message
if [ ! -z "${2}" ]; then
echo "${2}"
else
echo "Fatal error"
fi
# Exit with the proper code
exit ${1}
fi
}
./do-something.sh
check_error $? "Error message"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment