|
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 :
[axel@axel-asus plugins]$ unset foo [axel@axel-asus plugins]$ func() > { > echo "[a]=5 [b]=10" > } [axel@axel-asus 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 [axel@axel-asus plugins]$ echo ${foo[a]} [axel@axel-asus plugins]$ declare -a bar=( $(func) ) [axel@axel-asus plugins]$ echo ${bar[0]} [a]=5
[Prev in Thread] | Current Thread | [Next in Thread] |