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: Chris F.A. Johnson
Subject: Re: associative array assignment from the output of a function
Date: Fri, 22 Oct 2010 12:04:14 -0400 (EDT)
User-agent: Alpine 2.00 (LMD 1167 2008-08-23)

On Fri, 22 Oct 2010, Andreas Schwab wrote:

Axel <axel.azerty@laposte.net> writes:

After your answer, I checked and I think the error message is not
related to the variable name collision :

[axel@axel-asus plugins]$ unset foo
[axel@axel-asus plugins]$ func()
{
echo "[a]=5 [b]=10"
}
[axel@axel-asus plugins]$ declare -A foo=( $(func) )

$ declare -A foo=('[a]=5')

   Drop the qotes:

declare -A foo=( [a]=5 )

bash: foo: [a]=5: must use subscript when assigning associative array
$ eval "declare -A foo=($(echo '[a]=5'))"; echo ${foo[a]}
5

--
   Chris F.A. Johnson, <http://cfajohnson.com>
   Author:
   Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
   Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)



reply via email to

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