What does `inherit_errexit` change?
AdvancedConceptFunctions, exit codes, strict mode and traps
Answer
Before Bash 4.4 (and by default after, outside POSIX mode), command substitutions do not inherit set -e, so a failure inside $( ) does not stop the commands after it inside the substitution:
set -e
out=$(false; echo "kept going") # out="kept going", assignment status is 0
shopt -s inherit_errexit
out=$(false; echo "kept going") # subshell exits at false; assignment fails; script exits
We add shopt -s inherit_errexit to strict-mode headers on Bash 4.4+.
More on Functions, exit codes, strict mode and traps
How do you define a function, pass arguments and return a value?BeginnerWhat does `local` do, and what is dynamic scoping?AdvancedWhy is `local out=$(cmd)` a problem under `set -e`?AdvancedWhat are the conventional exit codes, and what do 126, 127, 130, 137 and 143 mean?BeginnerWhat does `set -e` do, and where does it NOT cause an exit?AdvancedExplain `set -euo pipefail` line by line, and add the `-E` flag.Beginner