Skip to content

test-and-or

Shellsuspiciousno fixdefault: warnshell/shellcheck

Reports a [ ] test that joins conditions with -a or -o.

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 [[ ]].

Reported
...
[ $x -eq 0 ]
[ -f a -o -f b ]
[ -a file ]
[[ -f a && -f b ]]
...
shell:
lint:
rules:
test-and-or: warn # off, warn (default), error

Enabled by the presets: shell/shellcheck.

Suppress one line with sudsy-disable-next-line test-and-or in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
shellcheck SC2166 full