Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: PATCH: param stuff and was: PATCH: 3.1.5-pws-12: _brace_parameter
- X-seq: zsh-workers 5840
- From: Peter Stephenson <pws@xxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxx
- Subject: Re: PATCH: param stuff and was: PATCH: 3.1.5-pws-12: _brace_parameter
- Date: Wed, 17 Mar 1999 11:08:21 +0100
- In-reply-to: ""Andrej Borsenkow""'s message of "Wed, 17 Mar 1999 12:59:19 NFT." <006201be705c$d3291660$21c9ca95@xxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
"Andrej Borsenkow" wrote:
> bor@itsrm2:~%> foo=(bar baz)
> bor@itsrm2:~%> print "${(@)${foo}[1]}"
> bar baz
> bor@itsrm2:~%> print "${${(@)foo}[1]}"
> b
>
> Could anybody explain, why?
It's actually completely predictable, once you know the rule.
In the first case the processing is
- "${foo}" giving quoted substituion, the word "bar baz"
- "${(@)...[1]}" where the ... is the result of the above. This
does array indexing on what you have already, because of the (@).
What you have already is a single word, so that is the first word of the
array and you get that.
In the second case, you get
- "${(@)foo}", giving the array (bar baz)
- "${...[1]}" on the result of that. There is no (@), so this is
a scalar substitution, so what we have so far is turned into a single
word and the [1] applies to characters in that, giving the `b'.
The rule is:
Substitution at each level only takes account of its own flags and
whether or not it is in double quotes in deciding how to process
what it has received from any nested substituion. It knows whether
or not that was an array, in case it needs to join the words or
select one or more of them, but it has no way of knowing about nested
flags and whether it should propagate them.
Maybe I can even invent something for the manual, if it's not going to
change.
--
Peter Stephenson <pws@xxxxxxxxxxxxxxxxx> Tel: +39 050 844536
WWW: http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy
Messages sorted by:
Reverse Date,
Date,
Thread,
Author