Created
September 4, 2014 18:23
-
-
Save chawkinsuf/4a65cc54b3337c7fcd95 to your computer and use it in GitHub Desktop.
Check for errors
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
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