shell - Bash: stop on error in sourced script -


in shell script executed, can abort on errors using set -e.

in sourced script, however, using set -e kill original shell if later command exits error status.

source set_e.sh ./exit_1.sh # shell dies 

a trivial solution set +e @ end of script, break parent's set -e if used (which may happen if wraps script in future).

how can abort-on-error functionality in sourced script?

it's impossible. can opt use subshell if want:

(     set -e     source another.sh ) 

only environment of calling script can never altered called script.

note: may important separate both commands newline , not use semicolon.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

c# - How do I get the Nth largest element from a list with duplicates, using LINQ? -

jsp - "Sending a redirect is forbidden after the response has been committed" in sendRedirect -