bash associative array key string with colon is giving error

前端 未结 1 1615
醉梦人生
醉梦人生 2021-01-25 01:29

I am creating an associative array of source and destination MAC addresses.

$ declare -a SrcDstMap
$ SrcDstMap[\"9c:4e:20:73:e2:72\"]=\"ff:ff:ff:ff:ff:ff\"
-bash         


        
相关标签:
1条回答
  • 2021-01-25 02:29

    That's not an associative array. You need to use declare -A, not declare -a.

    $ declare -A SrcDstMap
    $ SrcDstMap["9c:4e:20:73:e2:72"]="ff:ff:ff:ff:ff:ff"
    $ declare -p SrcDstMap
    declare -A SrcDstMap=([9c:4e:20:73:e2:72]="ff:ff:ff:ff:ff:ff" )
    

    declare -a creates a numerically indexed array, so the shell is trying to parse your index as a number.

    0 讨论(0)
提交回复
热议问题