bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: associative array assignment from the output of a function


From: Greg Wooledge
Subject: Re: associative array assignment from the output of a function
Date: Fri, 22 Oct 2010 12:19:13 -0400
User-agent: Mutt/1.4.2.3i

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

[Prev in Thread] Current Thread [Next in Thread]