Add -E when you want an installed Bash ERR trap to be inherited by functions, command substitutions, and commands running in subshell environments. -euo pipefail does not include that setting: -e controls eligible shell-exit behavior, -u reports unset-variable expansions, and pipefail changes pipeline status. None of those enables ERR-trap inheritance.
What does -E do?
-E is Bash’s short option for errtrace (also enabled with set -o errtrace). When set, an existing ERR trap is inherited by shell functions, command substitutions, and commands executed in a subshell environment. The GNU Bash Reference Manual, Edition 5.3, describes this behavior in its option documentation.
As an Amazon Associate I earn from qualifying purchases.
For example, the trap below is installed in the parent shell. With -E, it is also inherited when a failing command runs inside the function:
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →set -E
trap 'printf "ERR trap: status %s, command: %sn" "$?" "$BASH_COMMAND" >&2' ERR
fail() {
false
}
fail
Without -E, the function does not inherit the parent’s ERR trap. This is inheritance, not a promise to trap every nonzero status: Bash’s conditional-context rules still determine whether the trap runs.
#1 Best Overall
Why can the trap stay silent?
Bash does not run an ERR trap for several kinds of failing commands, even when the trap is available in that shell context. The manual describes exceptions similar to those for errexit. The command’s syntactic role matters:
- A command used as an
iforeliftest does not trigger the trap. - A command used as a
whileoruntilcondition does not trigger it. - Most commands in an
&&or||list do not trigger it; the final command is treated differently. - A non-final command in a pipeline does not trigger it. With
pipefail, the pipeline’s returned status can change, but pipeline position and the documented exceptions still matter. - A command whose status is inverted with
!does not trigger it.
So if adding -E appears not to help, check both where the failure occurs (for example, a function or command substitution) and how that command is used (for example, as an if condition). Those are separate questions.
How do -e, -E, and pipefail differ?
| Setting | What it changes | What it does not do |
|---|---|---|
-e / errexit |
May make Bash exit after an eligible command returns a nonzero status. | Does not make an ERR trap inherit into functions or subshell contexts; it also has conditional-context exceptions. |
-E / errtrace |
Makes an installed ERR trap inherited by functions, command substitutions, and commands in subshell environments. |
Does not remove the trap’s conditional-context exceptions or change a pipeline’s status rule. |
-o pipefail |
Makes a pipeline return the status of its rightmost nonzero command, or zero if all commands succeed. | Does not enable trap inheritance. |
The common form set -euo pipefail combines several useful but distinct behaviors. It is not shorthand for “run an ERR trap everywhere.” Add -E explicitly when inherited traps are wanted: set -Eeuo pipefail.
Free tools Windows power users keep installed
One-click scans. No signup required.
Does -E make command substitutions inherit -e too?
No. Trap inheritance and errexit inheritance are separate Bash behaviors. A command substitution runs in a subshell environment. Outside POSIX mode, Bash normally clears -e in that environment unless the separate inherit_errexit shell option is enabled. POSIX mode also changes this behavior. The Bash manual covers these command-execution rules in its subshell environment documentation.
Thus, -E can make the ERR trap available in a command substitution without making -e behave there as it does in the parent shell. If a script depends on both behaviors, configure and reason about them separately.
What should I check when debugging an ERR trap?
- Confirm the shell is Bash. These option names and rules are Bash-specific; do not assume another shell behaves the same way.
- Install the trap and enable inheritance. Use
trap '...' ERRandset -E(orset -o errtrace) if the trap must reach functions, command substitutions, or subshell environments. - Inspect the failure’s context. Determine whether it is an
if/whiletest, part of an AND/OR list, a non-final pipeline command, or preceded by!. These contexts can suppress the trap. - For a pipeline, separate status from trapping.
pipefailaffects the status returned by the pipeline; it does not by itself provideERR-trap inheritance. - For a command substitution, check
-eseparately. Decide whether its errexit behavior should be affected byinherit_errexitor POSIX mode.
The authoritative behavior is documented in the GNU Bash Reference Manual, Edition 5.3, last updated 18 May 2025. The details here are Bash semantics, not a general rule for every shell.
Quick Recap
Best Value
Rank #4
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




