From 21096f223fe231bf33bd4203acd8396071ac4e94 Mon Sep 17 00:00:00 2001 From: koalaman Date: Wed, 28 Dec 2016 18:56:21 -0800 Subject: [PATCH] Created SC2190 (markdown) --- SC2190.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 SC2190.md diff --git a/SC2190.md b/SC2190.md new file mode 100644 index 0000000..053cec5 --- /dev/null +++ b/SC2190.md @@ -0,0 +1,24 @@ +## Elements in associative arrays need index, e.g. array=( [index]=value ) . + +### Problematic code: + +```sh +declare -A foo +foo=( myvalue ) +``` + +### Correct code: + +```sh +declare -A foo +foo=( [key]=myvalue ) +``` +### Rationale: + +You appear to be initializing or appending an array element to an associative array without giving it an index. In an indexed array, elements will be auto-indexed by incremented characters. In associative arrays, the index must be given explicitly. + +This could happen because of invalid spaces or otherwise malformed index assignment, such as `array=( [key] = value )`. This should instead be `array=( [key]=value )`. + +### Exceptions: + +ShellCheck may be confused when a variable name is reused in different contexts. If shellcheck mistakenly believes the array is associated, please [[ignore]] this error. \ No newline at end of file