koalaman / shellcheck Public
SC1086
Joachim Ansorg edited this page Nov 12, 2021
·
4 revisions
Don't use $ on the iterator name in for loops.
Problematic code:
for $var in *
do
echo "$var"
doneCorrect code:
for var in *
do
echo "$var"
doneRationale:
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.