Error: must use subscript when assigning associative array

﹥>﹥吖頭↗ 提交于 2021-02-10 06:18:32

问题


I wanted a hashmap equivalent in bash (keys as string and values as a list of integers). So, I wrote the following code-

declare -A PUBS

PUBS=( "FEE":"[345, 342]" "FOO":"[1, 2, 44]" "BAR":"[23, 67]" )

However, I get an error saying must use subscript when assigning associative array.

What's wrong here?


回答1:


You're not using the correct syntax to specify the keys. It's [key]=value, not key:value. So it should be:

PUBS=( ["FEE"]="[345, 342]" ["FOO"]="[1, 2, 44]" ["BAR"]="[23, 67]" )


来源:https://stackoverflow.com/questions/55130017/error-must-use-subscript-when-assigning-associative-array

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!