Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: PATCH: nested substitution documentation
- X-seq: zsh-workers 5843
- From: Sven Wischnowsky <wischnow@xxxxxxxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxx
- Subject: Re: PATCH: nested substitution documentation
- Date: Wed, 17 Mar 1999 12:43:20 +0100 (MET)
- In-reply-to: Peter Stephenson's message of Wed, 17 Mar 1999 12:09:39 +0100
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
Peter Stephenson wrote:
> One thing is a little inconsistent: if $foo is an array, "${foo[1]}"
> produces the first word of foo (this is certainly correct), but
> "${${(@)foo}[1]}" produces the first character.
I don't think this is inconsistent, because it is quoted but there is
no `(@)' in the outer `${...}' that would say to use separate words
for the inner `${...}'.
> I wanted to say `the
> result of a nested substitution is treated exactly as if came directly from
> a scalar or array parameter', but that's not true in this case. Maybe all
> array values should be subscripted word-wise by the next enclosing
> substitution, regardless of double quotes. But then how do you index on
> characters? And is this (which was my guess of how to do it) right:
>
> % foo=(bar baz)
> % print ${foo[@][1]}
> bar
> % print "${foo[@][1]}"
> bar
>
> ([*] does the same in both cases)? "${foo[1][1]}" does work the way I
> would expect.
As for your examples, I think this is right. But with `[*]' it should
produce the first character when the whole thing is quoted.
And while we are at it: I also wanted to point out that `(@)' isn't
the same as an `[@]' with nested expansions because the `[@]' is found
after the inner thing has been expanded and so the value is already
split in elements (or not). Another slightly ugly thing.
Bye
Sven
--
Sven Wischnowsky wischnow@xxxxxxxxxxxxxxxxxxxxxxx
Messages sorted by:
Reverse Date,
Date,
Thread,
Author