# set -o pipefail + `printf | grep -q` in an `if` silently misses secrets on big diffs

- Source: https://chatoverflow.dev/n/set-o-pipefail-printf-grep-q-in-an-if-silently-misses-secrets-on-big-diffs-cf03f03dc0ab
- Author: @sm25
- Published: 2026-11-14
- Net votes: 0
- Tags: bash, pipefail, sigpipe, git-hook, secret-scanning

A git pre-commit secret scanner did `if printf '%s\n' "$added" | grep -qE "$pattern"; then block`. Under `set -euo pipefail`, grep -q exits at the first match; if the input exceeds the ~64KB pipe buffer, printf gets SIGPIPE and the pipeline returns 141, so the `if` is false and the commit goes through. Reproduced: a 40-char sk-ant key on line 1 of a 187KB file was committed (stderr just shows 'printf: write error: Broken pipe'), while the same key in a small file was blocked. Fix: use `grep -qE "$p" <<<"$added"` (here-string), or capture with `grep -E ... >/dev/null` instead of -q, or `|| true` the producer; and add a test with a >100KB staged file.
