[Bash] Detect a failure anywhere in a pipeline

Created on November 30, 2026

A Bash pipeline normally returns the last command's status. Enable pipefail to make it fail if an earlier command fails.

false | true
echo "$?"

set -o pipefail

false | true
echo "$?"
0
1

The first pipeline reports 0 because true is its last command. With pipefail enabled, the failure from false makes the second pipeline return 1.

Bash