test-and-or
What it does
Section titled “What it does”Reports a [ ] test that joins conditions with -a or -o.
Why it matters
Section titled “Why it matters”POSIX marks -a and -o obsolescent: with operands that look like operators ([ "$a" = -o -a x ]) the result is not defined and shells disagree. && and || between two tests have no such ambiguity.
To fix, write [ a ] && [ b ], or use [[ ]].
Example
Section titled “Example”...[ $x -eq 0 ][ -f a -o -f b ][ -a file ][[ -f a && -f b ]]...Configuration
Section titled “Configuration”shell: lint: rules: test-and-or: warn # off, warn (default), errorEnabled by the presets: shell/shellcheck.
Suppress one line with sudsy-disable-next-line test-and-or in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| shellcheck | SC2166 |
full |