Re: associative array assignment from the output of a function

2010-10-22 Thread Greg Wooledge
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 c

Re: associative array assignment from the output of a function

2010-10-22 Thread Andreas Schwab
"Chris F.A. Johnson" writes: > On Fri, 22 Oct 2010, Andreas Schwab wrote: > >> Axel writes: >> >>> After your answer, I checked and I think the error message is not >>> related to the variable name collision : >>> >>> [a...@axel-asus plugins]$ unset foo >>> [a...@axel-asus plugins]$ func()

Re: associative array assignment from the output of a function

2010-10-22 Thread Chris F.A. Johnson
On Fri, 22 Oct 2010, Andreas Schwab wrote: Axel writes: After your answer, I checked and I think the error message is not related to the variable name collision : [a...@axel-asus plugins]$ unset foo [a...@axel-asus plugins]$ func() { echo "[a]=5 [b]=10" } [a...@axel-asus plugins]$ declare

Re: associative array assignment from the output of a function

2010-10-22 Thread Andreas Schwab
Axel writes: > After your answer, I checked and I think the error message is not > related to the variable name collision : > > [a...@axel-asus plugins]$ unset foo > [a...@axel-asus plugins]$ func() >> { >> echo "[a]=5 [b]=10" >> } > [a...@axel-asus plugins]$ declare -A foo=( $(func) ) $ declare

Re: associative array assignment from the output of a function

2010-10-22 Thread Axel
Le 22/10/2010 16:21, Greg Wooledge a écrit : On Fri, Oct 22, 2010 at 02:59:37PM +0200, Axel wrote: Anyway, since this syntax works for assigning indexed arrays (even if it's a "hack"), should it works for associative array assignment ? Maintainers will decide I assume. But it doesn't. You used

Re: associative array assignment from the output of a function

2010-10-22 Thread Greg Wooledge
On Fri, Oct 22, 2010 at 02:59:37PM +0200, Axel wrote: > Anyway, since this syntax works for assigning indexed arrays (even if > it's a "hack"), should it works for associative array assignment ? > Maintainers will decide I assume. But it doesn't. You used a totally different syntax for your ind

Re: associative array assignment from the output of a function

2010-10-22 Thread Axel
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 ans

Re: associative array assignment from the output of a function

2010-10-22 Thread Axel
Le 22/10/2010 14:42, Greg Wooledge a écrit : Unreliable at best. How do you handle elements that have whitespace in them, for example? You have to know your data set, choose a delimiter that can't be in that set, and then write code to parse the output stream into elements. At this moment, I

Re: associative array assignment from the output of a function

2010-10-22 Thread Chet Ramey
> An easy example is better than an explanation: > > # Woks well > indexarray() > { > echo "5 6 7" > } > declare -a t1=( $(indexarray) ) > echo ${t1[1]} ${t1[0]} So you now have an indexed array named `t1'. > # Does not work > assocarray() > { > echo "[a]=5 [b]=6" > } > declare -A t1=(

Re: associative array assignment from the output of a function

2010-10-22 Thread Greg Wooledge
On Fri, Oct 22, 2010 at 10:26:27AM +0200, Axel wrote: > I try to assign an array from the output of a function. Unreliable at best. How do you handle elements that have whitespace in them, for example? You have to know your data set, choose a delimiter that can't be in that set, and then write c