Skip to content

test-grep-output

Shellsuspiciousno fixdefault: offshell/shellcheck

Reports a [[ ]] or [ -n ] / [ -z ] test of the output of a pipeline or command that ends in grep.

The output is captured only to see whether it is empty. grep -q does that, stops at the first match and sets the status.

To fix, write if grep -q ...; then.

Reported
...
[[ $a == "$b" ]]
...
x=$(echo "a" | tr a b)
[[ $(ps | grep x) ]]
...
for l in "$@"; do :; done
...
shell:
lint:
rules:
test-grep-output: warn # off (default), warn, error

Enabled by the presets: shell/shellcheck.

Suppress one line with sudsy-disable-next-line test-grep-output 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 SC2143 partial Only a [[ ]] or [ -n/-z ] over a substitution that contains grep.