Shell option interactions
set -o controls one family of shell options; shopt controls another. A preset is not a substitute for documenting the context. SHELLOPTS and BASHOPTS are readonly colon-separated lists of enabled options in their respective families. If exported, a normal child Bash can enable those options on startup; privileged modes have exceptions. A subshell environment is not the same as a new invocation: command substitutions normally clear errexit outside POSIX mode unless inherit_errexit is set, and conditional contexts can suppress it. lastpipe can preserve final pipeline state when job control is inactive. nocasematch changes pattern matching in conditionals and substitutions, whereas nocaseglob affects pathname expansion. localvar_inherit can change the initial value and attributes of local declarations. patsub_replacement controls whether an unquoted ampersand in replacement text stands for the matched portion. extdebug changes execution semantics as well as tracing, so enable only in a controlled debugging session. Check precise options with shopt -q name or [[ -o name ]]; isolate option experiments in subshells. Check each child result separately; the second substitution example is expected to stop with status 1. A successful parent printf does not propagate that failure.
Practical examples
Run each example as a separate script in a fresh noninteractive Bash 5.2 process and empty practice directory. Tests use C locale; do not enter expected output as code.
Compare substitution inheritance
bash -c 'set -e; shopt -u inherit_errexit; v=$(false; printf kept); printf "off=%s\n" "$v"' || exit 1bash -c 'set -e; shopt -s inherit_errexit; v=$(false; printf kept); printf "on=%s\n" "$v"'rc=$?[[ $rc == 1 ]] || exit 1printf 'on-status=%s\n' "$rc"Expected stdout:
off=kepton-status=1The second child stops when its substitution returns failure. The parent records that status.
Inspect exported option families
set -o pipefailshopt -s nullglobexport SHELLOPTS BASHOPTSbash -c '[[ -o pipefail ]] && printf "pipefail=on\n"; shopt -q nullglob && printf "nullglob=on\n"' Expected stdout:
pipefail=onnullglob=onThe new Bash reads both exported readonly lists on normal startup.
Different case matching modes
touch REPORT.TXT || exit 1shopt -s nocasematch[[ REPORT.TXT == *.txt ]] && printf 'conditional=yes\n'shopt -u nocaseglobprintf 'glob-off=%s\n' *.txtshopt -s nocaseglobprintf 'glob-on=%s\n' *.txtExpected stdout:
conditional=yesglob-off=*.txtglob-on=REPORT.TXTConditional matching and pathname matching have independent options.
Common mistakes
Never assume set -e makes every context fail-fast. A child invocation and a command substitution inherit different state.
Practice
Compare an isolated command substitution with inherit_errexit off and on. Record both output and status; then test a pattern with nocasematch enabled and disabled.
Next: Process and descriptor topology