Skip to content
Joachim Ansorg edited this page Nov 12, 2021 · 4 revisions

Instead of [ a && b ], use [ a ] && [ b ].

Problematic code:

[ "$1" = "-v" && -z "$2" ]

Correct code:

[ "$1" = "-v" ] && [ -z "$2" ]

Rationale:

&& can not be used in a [ .. ] test expression. Instead, make two [ .. ] expressions and put the && between them.

Exceptions:

None.

Related resources:

ShellCheck

Each individual ShellCheck warning has its own wiki page like SC1000. Use GitHub Wiki's "Pages" feature above to find a specific one, or see Checks.

Clone this wiki locally