Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk3 min

Why `set -euo pipefail` Didn’t Run My ERR Trap—and What `-E` Changes

`-E` enables Bash ERR-trap inheritance; `-e` and `pipefail` control different behavior. See the key exceptions and command-substitution distinction.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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.

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 if or elif test does not trigger the trap.
  • A command used as a while or until condition 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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What should I check when debugging an ERR trap?

  1. Confirm the shell is Bash. These option names and rules are Bash-specific; do not assume another shell behaves the same way.
  2. Install the trap and enable inheritance. Use trap '...' ERR and set -E (or set -o errtrace) if the trap must reach functions, command substitutions, or subshell environments.
  3. Inspect the failure’s context. Determine whether it is an if/while test, part of an AND/OR list, a non-final pipeline command, or preceded by !. These contexts can suppress the trap.
  4. For a pipeline, separate status from trapping. pipefail affects the status returned by the pipeline; it does not by itself provide ERR-trap inheritance.
  5. For a command substitution, check -e separately. Decide whether its errexit behavior should be affected by inherit_errexit or 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.

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.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.