mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC1086 (markdown)
25
SC1086.md
Normal file
25
SC1086.md
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
## 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).
|
||||||
|
|
||||||
|
### Contraindications
|
||||||
|
|
||||||
|
None.
|
Reference in New Issue
Block a user