From 0d6514521850c9f02af4f76033d8fbbd3a32d8bc Mon Sep 17 00:00:00 2001 From: koalaman Date: Sat, 8 Apr 2017 15:43:01 -0700 Subject: [PATCH] Created SC2208 (markdown) --- SC2208.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 SC2208.md diff --git a/SC2208.md b/SC2208.md new file mode 100644 index 0000000..600a4af --- /dev/null +++ b/SC2208.md @@ -0,0 +1,22 @@ +## Use `[[ ]]` or quote arguments to -v to avoid glob expansion. + +### Problematic code: + +```sh +[ -v foo[0] ] +``` + +### Correct code: + +```sh +[ -v 'foo[0]' ] +``` +### Rationale: + +With `[`, arguments will undergo glob expansion. If a file `foo0` exists when the problematic code is run, it will check for the variable `foo0` instead of the array entry `foo[0]`. If there additionally exists a `foo1`, it will simply fail with an error. + +Use `[[ ]]` or quote the argument. + +### Exceptions: + +None. \ No newline at end of file