How to get the status of a subcommand in a bash script that is invoked with -e? -
i want write bash script -e option stops on error, want allow specific line return error code different 0 , use in logic:
#/bin/bash -e do_something_and_return_errcode if [ $? -eq 2 ];     specific_stuff fi the script end in do_something_and_return_errcode. avoid doing
do_something_and_return_errcode || true but make $? return 0 , cannot use $pipestatus because not pipeline.
first, using set -e highly error-prone, , not universally agreed on practice.
that said, consider:
err=0 do_something_and_return_errcode || err=$? another option temporarily disable flag:
set +e ## disable effect of bash -e / set -e do_something_and_return_errcode; err=$? set -e ## ...and reenable flag after 
Comments
Post a Comment