Re: Indirect expansion and arrays

2012-10-02 Thread Chet Ramey
On 10/2/12 7:38 AM, Techlive Zheng wrote: > > >> On 7/29/10 4:55 PM, Bernd Eggink wrote: >>> It seems that indirect expansion doesn't work with arrays: >>> >>> $ a=(x y z) >>> $ b=a >>> $ echo "${!b[0]} ${!b[1]} ${!b[2]}" >>> x >>> >>> Is that intended? The documentation isn't explicit about it.

Re: Indirect expansion and arrays

2012-10-02 Thread Andreas Schwab
Techlive Zheng writes: > Combine with Chet Ramey's reply, a strucure like below would work. > > $ c=(a[0] a[1] a[2]) Careful. The elements are subject to filename expansion, so you need to quote them to be safe. Andreas. -- Andreas Schwab, sch...@linux-m68k.org GPG Key fingerprint = 58CA

Re: Indirect expansion and arrays

2012-10-02 Thread Techlive Zheng
sed literally. $ a=(x y z) $ b=a[@] $ echo "${!b}" # this would work Combine with Chet Ramey's reply, a strucure like below would work. $ c=(a[0] a[1] a[2]) $ echo "${!c[0]} ${!c[1]} ${!c[2]}" #this would work too -- View this message in context: http://old.nabble.com/Indirect-expansion-and-arrays-tp29300541p34504291.html Sent from the Gnu - Bash mailing list archive at Nabble.com.

Re: Indirect expansion and arrays

2010-12-09 Thread Mart Frauenlob
On 29.07.2010 22:55, Bernd Eggink wrote: It seems that indirect expansion doesn't work with arrays: $ a=(x y z) $ b=a $ echo "${!b[0]} ${!b[1]} ${!b[2]}" x Is that intended? The documentation isn't explicit about it. IMHO it would be very desirable to have a indirect expansion facility for arr

Re: Indirect expansion and arrays

2010-08-02 Thread Chet Ramey
On 7/29/10 4:55 PM, Bernd Eggink wrote: > It seems that indirect expansion doesn't work with arrays: > > $ a=(x y z) > $ b=a > $ echo "${!b[0]} ${!b[1]} ${!b[2]}" > x > > Is that intended? The documentation isn't explicit about it. It does, but it doesn't work in the way you are trying. The `!'

Re: Indirect expansion and arrays

2010-07-30 Thread Greg Wooledge
On Thu, Jul 29, 2010 at 10:55:51PM +0200, Bernd Eggink wrote: > It seems that indirect expansion doesn't work with arrays: ksh93 has a feature called nameref: myfunc() { nameref ref=$1 echo "array $1 has ${#ref[*]} elements" } I wouldn't mind seeing this in bash, though I'm not going to at

Re: Indirect expansion and arrays

2010-07-29 Thread Dennis Williamson
Oops, sorry, that converts all of a to a scalar b so ${b[0]} gives "x y z" and ${b[1]} gives nothing. On Thu, Jul 29, 2010 at 7:16 PM, Dennis Williamson wrote: > To make your example work try: > > $ b=a[*] > > or > > $ b...@] > > Otherwise, your indirection is telling b to look at a as a scalar.

Re: Indirect expansion and arrays

2010-07-29 Thread Dennis Williamson
To make your example work try: $ b=a[*] or $ b...@] Otherwise, your indirection is telling b to look at a as a scalar. This would give the same result: $ echo $a x On Thu, Jul 29, 2010 at 3:55 PM, Bernd Eggink wrote: > It seems that indirect expansion doesn't work with arrays: > > $ a=(x y z

Indirect expansion and arrays

2010-07-29 Thread Bernd Eggink
It seems that indirect expansion doesn't work with arrays: $ a=(x y z) $ b=a $ echo "${!b[0]} ${!b[1]} ${!b[2]}" x Is that intended? The documentation isn't explicit about it. IMHO it would be very desirable to have a indirect expansion facility for arrays. Otherwise there is only a choice bet