Skip to content

Instantly share code, notes, and snippets.

@naviat
Created March 25, 2020 11:03
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 naviat/bcd648dd4f0f3f30a017f3ebc0c14acc to your computer and use it in GitHub Desktop.
Save naviat/bcd648dd4f0f3f30a017f3ebc0c14acc to your computer and use it in GitHub Desktop.
#!/bin/sh
# Checks that the given error code is zero. If not, exits the script after printing the given error message.
# @param 1 the return code to check.
# @param 2 the error message to display in case the given error code is non-zero.
# @stdout nothing in case of success, the given error message otherwise.
ensureSuccess() {
if [[ $1 -ne 0 ]]; then
echo
echo "Error: $2"
echo "ABORTING!"
exit 1
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment