On Fri, Oct 22, 2010 at 12:04:14PM -0400, Chris F.A. Johnson wrote:
>    Drop the qotes:
> 
> declare -A foo=( [a]=5 )

That misses the point.  The original poster was trying to initialize
an associative array using key/value pairs that were being fed through
a substitution.  Like this, but using command substitution from a
function instead:

imadev:~$ x='[a]=5'
imadev:~$ unset foo
imadev:~$ declare -A foo=( $x )
bash: foo: [a]=5: must use subscript when assigning associative array

Doing this requires eval, but I would not do that.  I'd rewrite the code
so that I don't have to do this in the first place.

Reply via email to