[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Indirect expansion and arrays
From: |
Chet Ramey |
Subject: |
Re: Indirect expansion and arrays |
Date: |
Mon, 02 Aug 2010 15:25:04 -0400 |
User-agent: |
Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.1.7) Gecko/20100111 Lightning/1.0b1 Thunderbird/3.0.1 |
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 `!' binds to
an entire variable reference, in this case 'b[0]'. The idea behind that
was to permit the use of an array of variable names, for instance, that
could be easily referenced using indirect expansion.
The following code will display
"x variable y variable z variable"
a=(x y z)
x='x variable'
y='y variable'
z='z variable'
echo "${!a[0]} ${!a[1]} ${!a[2]}"
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU chet@case.edu http://cnswww.cns.cwru.edu/~chet/
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: Indirect expansion and arrays,
Chet Ramey <=