Skip to content

Instantly share code, notes, and snippets.

@Kerruba
Kerruba / bash-try-catch.sh
Created March 15, 2017 12:07 — forked from stepf/bash-try-catch.sh
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