Bash: Saving exit code of command in `-e` script

Viewed 80

I've got a Bash script that's run with the -e flag. At some point, I want to run a Bash command, and continue whether it succeeded or not. I also want to have a variable that saves whether it succeeded or not, because later I want to do an if clause that's executed only if that command failed.

Is that possible? How?

1 Answers

I think that set -e does not quit the script if the return code is checked. Maybe you can execute your command like:

if <cmd>; then
    echo Success
    SUCCES=yes
else
    echo failure
    SUCCES=no
fi
Related