Skip to content
Vidar Holen edited this page Oct 4, 2015 · 2 revisions

Instead of '[ 1 ]', use 'true'.

Problematic code:

while [ 1 ]
do
  echo "infinite loop"
done

Correct code:

while true
do
  echo "infinite loop"
done

Rationale:

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

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

If you instead use true, the value is actually considered and can be inverted by replacing with false.

On bash, you can also use (( 1 )), which evaluates to true much like in C. (( 0 )) is similarly false.

Exceptions:

None.

ShellCheck

Each individual ShellCheck warning has its own wiki page like SC1000. Use GitHub Wiki's "Pages" feature above to find a specific one, or see Checks.

Clone this wiki locally
You can’t perform that action at this time.