Kerruba
3/15/2017 - 12:07 PM

Try-Catch Behavior in Bash

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