Exit status 127 in pipelines with set -e and pipefail
0 reputation · 09 Dec 2020, 22:01 UTC
This question examines how bash propagates intermediate pipeline failures when set -e and pipefail are both active, given the documented exception list for set -e and the arithmetic command (( )) status behavior. The goal is to identify predictable control-flow paths that surface silent mid-pipeline failures without relying on external tooling. Constraints include the bash manual's exception conditions for set -e (commands in if, while, or until conditions, &&/|| lists, pipeline elements except the last, !-prefixed commands) and the fact that (( )) returns exit status 1 when the evaluated expression yields zero, which can abort loops starting from zero under strict mode. The unresolved decision centers on whether explicit per-command checks or set -euo pipefail offers more reliable error detection in scripts targeting bash 4.4 and later.
Under what conditions does pipefail override set -e's exception for a failing command in a && list? Does ((i++)) from zero trigger script exit under set -euo pipefail? How does a non-zero return from command_not_found_handle interact with set -e and pipefail in a single script?