'Bash associative arrays be initialized in a (...) list?
Can bash associative arrays be initialized in a (...) list similarly to non associative arrays? Format?
Updating to give an answer using the comments.
Yes, the format depends on the version of bash. For GNU bash, version 4.4.23(1), it is declare -A AR=([key1]=value1 [key2]=value2)
The available default format can be found out with declare -p AR
Solution 1:[1]
Yes. For example:
declare -A assoc=(["1 2"]="3 4" ["a b"]="c d" )
If you've got a populated associated array (assoc say) and you want to see how to see how it could be initialized run
declare -p assoc
That's how I got the initialization command above.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | pjh |
