Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: field splitting behavior
- X-seq: zsh-users 4511
- From: Zefram <zefram@xxxxxxxx>
- To: zsh-users@xxxxxxxxxxxxxx
- Subject: Re: field splitting behavior
- Date: Tue, 27 Nov 2001 19:21:34 +0000
- In-reply-to: <15363.58319.278466.686768@xxxxxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <15363.58319.278466.686768@xxxxxxxxxxxxxxxxxxxxxxx>
Paul Lew wrote:
>> var='foobar'
>> echo ${(@)${(s/:/)var}[1]}
>f
>
>So why it did field splitting on each character when there is no
>separator ':' found? I would expect 'foobar' on the output.
The result of the splitting is a single word "foobar", as you expect.
This is then treated as a scalar, not an array, and so the [1] extracts
the first character, instead of the first element. The (@) doesn't do
what you think it does (it only has an effect where double quotes are
used). I don't see any easy way to force the result of a ${(s...)...}
to be treated as an array, so I'll have to leave that to the expansion
wizards.
-zefram
Messages sorted by:
Reverse Date,
Date,
Thread,
Author