Created
September 15, 2020 16:31
-
-
Save jsheedy/51ad022d676d55861603f6f68fec55cf to your computer and use it in GitHub Desktop.
bash run() - exit script if subprocess fails
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
function run() { | |
# usage: run "command string --with-args" | |
cmd_output=$(eval $1) | |
return_value=$? | |
if [ $return_value != 0 ]; then | |
echo "Command $1 failed" | |
exit -1 | |
else | |
echo "output: $cmd_output" | |
echo "Command succeeded." | |
fi | |
return $return_value | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment