Interview Prep/Shell Scripting/Functions, exit codes, strict mode and traps

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+.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Functions, exit codes, strict mode and traps