Skip to main content
blog.philz.dev

Pipefail Fail

$bash -c 'set -euo pipefail; (echo hi; sleep 2; echo bye) | grep -q hi'; echo $?
141

What the?!?! That should succeed. We're printing "hi\nbye", and surely grep is finding it.

Turns out that SIGPIPE (13) is 128+13=141, and the non-zero exit code is because the (echo hi; sleep 2; echo bye) part of the pipeline is failing with SIGPIPE.

There are lots of solutions, but the simplest one is to not use -q, which not only does "quiet" but also exits at first match, causing the failure.

TIL. 😡