Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: ${^var} and word splitting
On Mon, 24 Nov 2014 08:55:08 -0800
Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Nov 24, 3:55pm, Peter Stephenson wrote:
> } Subject: Re: ${^var} and word splitting
> }
> } On Mon, 24 Nov 2014 15:26:28 +0000
> } Stephane Chazelas <stephane.chazelas@xxxxxxxxx> wrote:
> } > If I understand correctly, in zsh the removing of those are
> } > accounted to null-removal in things like:
> } >
> } > $ print -l $=a
> } > 1
> } > 2
> } > 3
> } >
> } > But then it's not clear why they are removed there and not in:
> } >
> } > a=':a::b:'
> } > IFS=:
> } > print -l $=a
> }
> } I looked at the code and you're exactly right: it's not clear.
>
> Isn't it always the case that *whitespace* in IFS is treated differently
> than non-whitespace? E.g. consecutive whitespace is treated as a single
> character, so (IFS=" " "a b") is two words but (IFS=: "a::b") is three?
Yes, that's right, but what zsh is doing is a bit funny: as Stephane
notes, in other shells you don't get the null arguments in the first
place if the special whitespace rule is being followed, it's not a
question of whether they get removed later or not. At least I think
so --- splitting is implicit in other shells so I may just not
be quite doing the equivalent. Here's what I did in bash:
$ fn() { local arg; for arg in "$@"; do echo $arg; done; }
$ fn2() { fn $1; }
$ fn2 ' a b c '
a
b
c
$
So that $1 argument to fn2 gets split in the way we're talking about,
while within fn we make sure we pick up every piece that's been
split from it. This definitely looks different from zsh.
However, I think what you mention is indeed the source of the
difference Stephane noticed, because doubling a whitespace character in
IFS does have the documented effect of making it work the other way
(see the zshparam manual; this is without the patch which is
obviously not a correct fix):
% a=' a b c '
% print $=a
a b c
% print -l $=a
a
b
c
% IFS=' ' # two spaces
% print -l $=a
a
b
c
%
So that explains the mysterious allownull whatever the explanation for
the implementation.
pws
Messages sorted by:
Reverse Date,
Date,
Thread,
Author