Skip to content
Vidar Holen edited this page Jan 21, 2015 · 4 revisions

Don't use $ on the iterator name in for loops.

Problematic code:

for $var in *
do
  echo "$var"
done

Correct code:

for var in *
do
  echo "$var"
done

Rationale:

The variable is named var, and can be expanded to its value with $var.

The for loop expects the variable's name, not its value (and the name can not be specified indirectly).

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