Pattern: Use of [ false ]
in shell script
Issue: -
[ str ]
checks whether str
is non-empty. It doesn't matter if str
is false
, it will still be evaluated for non-emptiness.
Instead, use the command false
which -- as the manual puts it -- does nothing, unsuccessfully.
Example of incorrect code:
if [ false ]
then
echo "triggers anyways"
fi
Example of correct code:
if false
then
echo "never triggers"
fi