From bc97a93e260efb931f203ba2b8d70b5affc9cbad Mon Sep 17 00:00:00 2001 From: koalaman Date: Sat, 31 Dec 2016 13:45:52 -0800 Subject: [PATCH] Created SC2201 (markdown) --- SC2201.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 SC2201.md diff --git a/SC2201.md b/SC2201.md new file mode 100644 index 0000000..3c69b3b --- /dev/null +++ b/SC2201.md @@ -0,0 +1,26 @@ +## Brace expansion doesn't happen in [[ ]]. Use a loop. + +### Problematic code: + +```sh +[[ "$file" = index.{htm,html,php} ]] && echo "This is the main file" +``` + +### Correct code: + +```sh +for main in index.{htm,html,php} +do + [[ "$file" = "$main" ]] && echo "This is the main file" +done +``` + +### Rationale: + +Brace expansions doesn't happen in `[[ ]]`. They will just be interpreted literally. + +Instead, use a `for` loop to iterate over values, and apply your condition to each. + +### Exceptions: + +None. \ No newline at end of file