zsh-users
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: Zsh hackers list <zsh-users@zsh.org>
Subject: Re: ${^var} and word splitting
Date: Mon, 24 Nov 2014 17:22:49 +0000	[thread overview]
Message-ID: <20141124172249.53419bd7@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <141124085508.ZM16833@torch.brasslantern.com>

On Mon, 24 Nov 2014 08:55:08 -0800
Bart Schaefer <schaefer@brasslantern.com> 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@gmail.com> 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


  reply	other threads:[~2014-11-24 17:23 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-24  9:56 Stephane Chazelas
2014-11-24 11:12 ` Peter Stephenson
     [not found] ` <20141124111201.161d8cf2__23261.8202259347$1416827641$gmane$org@pwslap01u.europe.root.pri>
2014-11-24 15:26   ` Stephane Chazelas
2014-11-24 15:55     ` Peter Stephenson
2014-11-24 16:55       ` Bart Schaefer
2014-11-24 17:22         ` Peter Stephenson [this message]
     [not found]     ` <20141124155524.0739b3ec__26419.4987401881$1416845250$gmane$org@pwslap01u.europe.root.pri>
2014-11-24 21:18       ` Stephane Chazelas
2014-11-25  7:49         ` Bart Schaefer
     [not found]         ` <141124234931.ZM17259__8246.8130779036$1416901919$gmane$org@torch.brasslantern.com>
2014-11-25 12:12           ` Stephane Chazelas

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20141124172249.53419bd7@pwslap01u.europe.root.pri \
    --to=p.stephenson@samsung.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).