Open wybodekker opened 3 years ago
# shellcheck shell=bash
foo () {
declare -a cmd=(1 2 3)
echo "func ${cmd[*]}"
}
cmd="bar"
foo
echo "main ${cmd[*]}"
results in
Line 6: cmd="bar" ^-- SC2178: Variable was used as an array but is now assigned a string.
while cmd
is local to the function foo
only and does not spill out
For bugs
shellcheck --version
or 'online'): online and local version 0.7.1Here'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[*]}"
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 ) .