local associative array seen as global
Author: wybodekkerCreated Mar 11, 2021Updated Sep 26, 2026
For bugs
- Rule Id: SC2190
- My shellcheck version (
shellcheck --versionor 'online'): online and local version 0.7.1 - I tried on shellcheck.net and verified that this is still a problem on the latest commit
- It's not reproducible on shellcheck.net, but I think that's because it's an OS, configuration or encoding issue
Here's a snippet or screenshot that shows the problem:
#!/bin/bash
f() {
local -A map
map[x]=assoc
map[y]=array
echo "local map: ${map[*]}"
}
g() {
local -a map
map+=(index)
map+=(arr)
}
f
echo "x: ${map[x]} y: ${map[y]}"
g
echo "global map: ${map[*]}"Here's what shellcheck currently says:
Line 12 SC2190: Elements in associative arrays need index, e.g. array=( [index]=value ) .
Line 13 SC2190: Elements in associative arrays need index, e.g. array=( [index]=value ) .Here's what I wanted or expected to see:
it should give error code SC2034 instead: map appears unused. Verify...
Source: koalaman/shellcheck