Skip to content

Files

Latest commit

 

History

History
31 lines (21 loc) · 568 Bytes

SC2158.md

File metadata and controls

31 lines (21 loc) · 568 Bytes

Pattern: Use of [ false ] in shell script

Issue: -

Description

[ 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

Further Reading