Skip to content

test-negated-empty

Shellstyleno fixdefault: offshell/shellcheck

Reports a test that negates -z or -n, as in [ ! -z "$x" ].

-n is the opposite of -z, so the negation can be dropped, and a double negative is hard to read.

To fix, write [ -n "$x" ].

Reported
...
[ -a file ]
[[ -f a && -f b ]]
[ ! -z "$x" ]
[ ! -n "$x" ]
[ -z "$x" ]
...
shell:
lint:
rules:
test-negated-empty: warn # off (default), warn, error

Enabled by the presets: shell/shellcheck.

Suppress one line with sudsy-disable-next-line test-negated-empty 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 SC2236 full