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: Axel
Subject: Re: associative array assignment from the output of a function
Date: Fri, 22 Oct 2010 15:48:31 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.9.2.11) Gecko/20101013 Lightning/1.0b2 Thunderbird/3.1.5

Le 22/10/2010 14:56, Chet Ramey a écrit :

And you're trying to redeclare it as an associative array here.  The
variable already exists; you can't convert it between array types;
and bash tells you this.  If you want an associative array, unset the
variable before you declare it.

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

address@hidden plugins]$ unset foo
address@hidden plugins]$ func()
> {
> echo "[a]=5 [b]=10"
> }
address@hidden plugins]$ declare -A foo=( $(func) )
-bash: foo: [a]=5: must use subscript when assigning associative array
-bash: foo: [b]=10: must use subscript when assigning associative array
address@hidden plugins]$ echo ${foo[a]}

address@hidden plugins]$ declare -a bar=( $(func) )
address@hidden plugins]$ echo ${bar[0]}
[a]=5






reply via email to

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