Skip to content

Latest commit

 

History

History
31 lines (21 loc) · 558 Bytes

SC2159.md

File metadata and controls

31 lines (21 loc) · 558 Bytes

Pattern: Use of [ 0 ] instead of false

Issue: -

Description

[ str ] checks whether str is non-empty. It doesn't matter if str is 0, 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 [ 0 ]
then
  echo "always triggers"
fi

Example of correct code:

if false
then
  echo "never triggers"
fi

Further Reading