Skip to content

.tip

· one of the small things

PIPESTATUS tells you which command in a pipe failed

After a pipe, $? is the exit code of the last command. With set -o pipefail the pipe fails if any part of it failed, but you still don't know which part.

cmd_a | cmd_b | cmd_c
echo "${PIPESTATUS[@]}"   # e.g. 0 1 0: cmd_b failed

In zsh it's lowercase pipestatus. Log it in the error branch and the failing stage ends up in the log.

shell