[EMAIL PROTECTED] wrote:
> Help!
>
> Why does this not work?
>
> n=a
> a=( x y z)
> echo "$!n[0]"
> echo "$!n[1]"
> echo "$!n[2]"
>
>
> only value i get is a[0]
First of all, you need the braces. Otherwise you get $!, followed by
n[0], n[1], and n[2], respectively.
Second, once you add the braces, the entire parameter is indirected:
n[0], n[1], or n[2]. Only the first expands to anything, since
subscripting a scalar with 0 is equivalent to expanding it without
the array syntax. So you get 'a', since $n == a, and try to indirect
through `$a'. Since referencing an array variable without using array
syntax is equivalent to referencing element 0, you get a[0], or x.
Bash uses the entire rest of the parameter portion of the expansion
as the part to expand and perform indirection on; this is documented in
the manual page.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
( ``Discere est Dolere'' -- chet )
Live Strong. No day but today.
Chet Ramey, ITS, CWRU [EMAIL PROTECTED] http://cnswww.cns.cwru.edu/~chet/
_______________________________________________
Bug-bash mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-bash