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: 9c: value too great for base (error token is "9c")
$ SrcDstMap["fc:4e:20:73:e2:72"]="ff:ff:ff:ff:ff:ff"
-bash: fc:4e:20:73:e2:72: syntax error in expression (error token is ":4e:20:73:e2:72")
How can I tell bash that the given key is a whole string.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With