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

[ false ] is true. Remove the brackets

Problematic code:

if [ false ]
then
  echo "triggers anyways"
fi

Correct code:

if false
then
  echo "never triggers"
fi

Rationale:

[ str ] checks whether str is non-empty. It doesn't matter if str is false, it will still be evaluated for non-emptyness.

Instead, use the command false which -- as the manual puts it -- does nothing, unsuccessfully.

Exceptions:

None

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