From 9f049856d4e7426f26ed002abf5cc7537f680f3c Mon Sep 17 00:00:00 2001 From: koalaman Date: Sat, 5 Apr 2014 14:55:11 -0700 Subject: [PATCH] Created SC2125 (markdown) --- SC2125.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 SC2125.md diff --git a/SC2125.md b/SC2125.md new file mode 100644 index 0000000..815ca1e --- /dev/null +++ b/SC2125.md @@ -0,0 +1,23 @@ +## Brace expansions and globs are literal in assignments. Quote it or use an array. + +### Problematic code: + + foo={1..9} + echo $foo + +### Correct code: + + foo=( {1..9} ) + echo "${foo[@]}" + +### Rationale: + +`echo *.png {1..9}` expands to all png files and numbers from 1 to 9, but `var=*.png` or `var={1..9}` will just assign the literal strings `'*.png'` and `'{1..9}'`. + +To make the variable contain all png files or 1 through 9, use an array as demonstrated. + +If you intended to assign these values as literals, quote them (e.g. `var="*.png"`). + +### Contraindications + +None. \ No newline at end of file