Last active
August 29, 2015 14:11
-
-
Save kcha/f3d980a782d7246b4cc6 to your computer and use it in GitHub Desktop.
Check exit status after running a command in bash
This file contains hidden or 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
#!/bin/bash | |
check_exit_status() { | |
# Checks the latest exit status and exits if status is non-zero | |
# usage: check_exit_status $? "my_function" | |
EXITSTAT=$1 | |
FUNC=$2 | |
if [ "$EXITSTAT" -ne "0" ]; then | |
echo "=> ["`date`"] $FUNC failed" | |
exit $EXITSTAT | |
else | |
echo "=> ["`date`"] $FUNC OK" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment