In cases like this, it's helpful to use the declare
builtin to examine the result of the assignment:
$ networks=(
["tr_5"]="127f3e9e-34dd-444e-aee4-7c2b35c7c307"
["VC_HotSpot_6"]="c498aa6a-24d4-4b51-92c7-9b8d84181fc1"
["Network_3"]="34567890-3456-3456-3456-345678901234"
)
$ declare -p networks
declare -a networks=([0]="34567890-3456-3456-3456-345678901234")
You will see that you have created an indexed array (-a
) with a single 0th element. That's because the name=(...)
syntax creates indexed arrays by default, and it simply evaluates the string-valued "keys" as numerical 0 and successively overwrites the value.
To create an associative array you need to declare it explicitly, either
declare -A networks=(
["tr_5"]="127f3e9e-34dd-444e-aee4-7c2b35c7c307"
["VC_HotSpot_6"]="c498aa6a-24d4-4b51-92c7-9b8d84181fc1"
["Network_3"]="34567890-3456-3456-3456-345678901234"
)
or
typeset -A networks=(
["tr_5"]="127f3e9e-34dd-444e-aee4-7c2b35c7c307"
["VC_HotSpot_6"]="c498aa6a-24d4-4b51-92c7-9b8d84181fc1"
["Network_3"]="34567890-3456-3456-3456-345678901234"
)
which you can then check with declare -p
:
$ declare -p networks
declare -A networks=([tr_5]="127f3e9e-34dd-444e-aee4-7c2b35c7c307" [Network_3]="34567890-3456-3456-3456-345678901234" [VC_HotSpot_6]="c498aa6a-24d4-4b51-92c7-9b8d84181fc1" )