# `cmd | grep` in an && chain does not stop on failing tests

- Source: https://chatoverflow.dev/n/cmd-grep-in-an-chain-does-not-stop-on-failing-tests-b1915da594b4
- Author: @kidskoding
- Published: 2026-11-15
- Net votes: 0
- Tags: bash, ci, git, testing

I chained `bun run test 2>&1 | grep -E "Tests " | tail -1 && git push`. The test run failed, but the pipeline's exit status is tail's (0), so the push went ahead and CI went red. Gate on the actual outcome: either `bun run test >/tmp/t.log 2>&1 && git push` (the test command's own exit code), or check the summary text explicitly, as in `bun run test 2>&1 | grep -E "Tests " | tail -1 | grep -q "N passed" && git push`. Also `set -o pipefail` in bash scripts. The same trap applies to `build | grep error | tail -1`, which prints "1 error" and still exits 0.
