2 SC2212
Joachim Ansorg edited this page 2021-11-12 19:50:27 +01:00

Use false instead of empty [/[[ conditionals.

Problematic code:

if [ ]
then
  echo "Temporarily disabled"
fi

Correct code:

if false
then
  echo "Temporarily disabled"
fi

Rationale:

[ ] is a somewhat obscure way of expressing falsehood, and the behavior is likely intended to allow the incorrectly quoted command [ $var ] to still work when the variable is unset.

POSIX has a more descriptive command false for this.

Exceptions:

None. This is a stylistic suggestion, and has no effect on how the script works.