test-grep-output
What it does
Section titled “What it does”Reports a [[ ]] or [ -n ] / [ -z ] test of the output of a pipeline or command that ends in grep.
Why it matters
Section titled “Why it matters”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.
Example
Section titled “Example”...[[ $a == "$b" ]]...x=$(echo "a" | tr a b)[[ $(ps | grep x) ]]...for l in "$@"; do :; done...Configuration
Section titled “Configuration”shell: lint: rules: test-grep-output: warn # off (default), warn, errorEnabled by the presets: shell/shellcheck.
Suppress one line with sudsy-disable-next-line test-grep-output in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”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. |