Skip to content

Instantly share code, notes, and snippets.

@stepf
Created October 28, 2014 09:50
Show Gist options
  • Save stepf/8b737db6dab97896b649 to your computer and use it in GitHub Desktop.
Save stepf/8b737db6dab97896b649 to your computer and use it in GitHub Desktop.
Try-Catch Behavior in Bash
#!/bin/bash --
# Note -- will make script continue despite errors
echo "Some command that fails"
RETURN_CODE=$?; #capture error code here (if any)
echo "Cleanup before script is allowed to fail"
[[ $RETURN_CODE -ne 0 ]] && exit $RETURN_CODE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment