From dcbc7aa5317f4db58b4f08b2939f6bc7420228b4 Mon Sep 17 00:00:00 2001 From: koalaman Date: Sun, 9 Nov 2014 16:29:24 -0800 Subject: [PATCH] Created SC1086 (markdown) --- SC1086.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 SC1086.md diff --git a/SC1086.md b/SC1086.md new file mode 100644 index 0000000..bd5ab16 --- /dev/null +++ b/SC1086.md @@ -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. \ No newline at end of file