Bash array keys conflicting with existing variables -


my expectation has been keys in bash arrays interpreted literals, seems that's not case. example, following works expected:

$ declare -a mymap $ mymap[foo]="bar" 

no problem there, have array key, literally "foo". when set environment variable same name key, , put special characters in it, produces parse error:

$ declare -a mymap $ export foo=" > " $ mymap[foo]="bar" -bash: >: syntax error: operand expected (error token ">") $ mymap["foo"]="bar" -bash: >: syntax error: operand expected (error token ">") $ mymap['foo']="bar" -bash: >: syntax error: operand expected (error token ">") 

can explain i'm missing here? i'm using bash version 4.3.33.

use -a declare associative array string keys. -a creates indexed array keys evaluated in arithmetic context.

$ declare -a mymap $ export foo=' > ' $ mymap[foo]="bar" $ echo "${mymap[foo]}" bar $ declare -p mymap declare -a mymap='([foo]="bar" )'