From 45f29a995157bf472fe4fc412d9efcca75997910 Mon Sep 17 00:00:00 2001 From: koalaman Date: Sat, 24 Sep 2016 14:58:30 -0700 Subject: [PATCH] Created SC2184 (markdown) --- SC2184.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 SC2184.md diff --git a/SC2184.md b/SC2184.md new file mode 100644 index 0000000..f423c07 --- /dev/null +++ b/SC2184.md @@ -0,0 +1,24 @@ +## Quote arguments to unset so they're not glob expanded. + +### Problematic code: + +```sh +unset foo[index] +``` + +### Correct code: + +```sh +unset 'foo[index]' +``` +### Rationale: + +Arguments to `unset` are subject to regular glob expansion. This is especially relevant when unsetting indices in arrays, where `[..]` is considered a glob character group. + +In the problematic code, having a file called `food` in the current directory will result in `unset foo[index]` expanding to `unset food`, which will silently succeed without unsetting the element. + +Quoting so that the `[..]` is passed literally to `unset` solves the issue. + +### Exceptions: + +None. \ No newline at end of file