I want to write a bash script with -e option so it stops on any error, but want to allow a specific line to return an error code different to zero and use it in the logic:
#/bin/bash -e
do_something_and_return_errcode
if [ $? -eq 2 ]; then
specific_stuff
fi
The script would normally end in do_something_and_return_errcode
. I could avoid by doing
do_something_and_return_errcode || true
but this would make $?
return 0
and I cannot use $PIPESTATUS
because this is not a pipeline.