4 SC1086
Joachim Ansorg edited this page 2021-11-12 10:46:29 +01:00

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.