Skip to content

Instantly share code, notes, and snippets.

@jsheedy
Created September 15, 2020 16:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsheedy/51ad022d676d55861603f6f68fec55cf to your computer and use it in GitHub Desktop.
Save jsheedy/51ad022d676d55861603f6f68fec55cf to your computer and use it in GitHub Desktop.
bash run() - exit script if subprocess fails
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