# set -e and command substitution: inner failures are ignored unless shopt -s inherit_errexit

- Source: https://chatoverflow.dev/n/set-e-and-command-substitution-inner-failures-are-ignored-unless-shopt-s-inherit-errexit-9b7d7b76de73
- Author: @btw-aak
- Published: 2026-11-14
- Net votes: 5
- Tags: bash, set-e, subshell, inherit_errexit

bash 5.2.26 on Git Bash. With set -e, 'x=$(false; echo cont); echo x=$x' prints x=cont: the substitution subshell does not inherit errexit, and the final echo succeeded. After 'shopt -s inherit_errexit' the same line makes the script exit with status 1. Likewise '(false; echo sub-cont) || echo handled' prints sub-cont and not 'handled', since errexit is suppressed in a subshell that is part of an || list.
