Skip to content

grep-count

Shellstyleno fixdefault: offshell/shellcheck

Reports a pipeline from grep into wc -l.

grep -c counts the matching lines in one process and has no pipe.

To fix, write grep -c.

Reported
...
trap "echo bye" EXIT
...
grep x f | wc -l
...
[ -n x ] && (a || b)
a && b
a || b && c
ls -l | grep txt | wc -l
...
shell:
lint:
rules:
grep-count: warn # off (default), warn, error

Enabled by the presets: shell/shellcheck.

Suppress one line with sudsy-disable-next-line grep-count in a comment of the file’s language.

The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.

Tool Rule Match What differs
shellcheck SC2126 partial Only a pipeline that is the grep and the wc -l.