SC2159
Joachim Ansorg edited this page Nov 12, 2021
·
3 revisions
[ 0 ] is true. Use false instead.
Problematic code:
if [ 0 ]
then
echo "always triggers"
fiCorrect code:
if false
then
echo "never triggers"
fiRationale:
[ str ] checks whether str is non-empty. It doesn't matter if str is 0, it will still be evaluated for non-emptyness.
Instead, use the command false which -- as the manual puts it -- does nothing, unsuccessfully.
Exceptions:
None