Skip to content

Files

Latest commit

 

History

History
39 lines (27 loc) · 899 Bytes

SC2160.md

File metadata and controls

39 lines (27 loc) · 899 Bytes

Pattern: Use of [ true ] instead of true

Issue: -

Description

This is a stylistic suggestion to use true instead of [ true ].

[ true ] seems to suggest that the value "true" is somehow relevant to the statement. This is not the case, it doesn't matter. You can replace it with [ false ] or [ wombat ], and it will still always be true:

String In brackets Outside brackets
true true true
false true false
wombat true unknown command

It's therefore better to use it without brackets, so that the "true" actually matters.

Example of incorrect code:

if [ true ]
then
  echo "always triggers"
fi

Example of correct code:

if true
then
  echo "always triggers"
fi

Further Reading