From 8c01328a600f197ba352ffe262796cb1858f4673 Mon Sep 17 00:00:00 2001 From: koalaman Date: Wed, 28 Dec 2016 18:41:58 -0800 Subject: [PATCH] Created SC2192 (markdown) --- SC2192.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 SC2192.md diff --git a/SC2192.md b/SC2192.md new file mode 100644 index 0000000..796ff36 --- /dev/null +++ b/SC2192.md @@ -0,0 +1,25 @@ +## This array element has no value. Remove spaces after = or use "" for empty string. +### Problematic code: + +```sh +array=([1]=one [2]= two) +``` + +### Correct code: + +```sh +array=([1]=one [2]=two) +``` +### Rationale: + +You have an array element on the form `[index]=`. The shell will interpret this as an independent element with index `index` and value ``. + +This may happen as part of the expression `[index]= value`, where the space is not allowed and causes the shell to interpret it as `[index]="" [index+1]=value`. + +If you wanted the element to have a value, remove the spaces after `=`, e.g. `[index]=value`. + +If you wanted to assign an empty string, explicitly use emtpy quotes: `[index]=""`. This makes no difference to the shell, but will make your intention clear to shellcheck and other humans. + +### Exceptions: + +None. \ No newline at end of file