zsh-users
 help / color / mirror / code / Atom feed
From: Stephane Chazelas <stephane.chazelas@gmail.com>
To: Peter Stephenson <p.stephenson@samsung.com>
Cc: Zsh hackers list <zsh-users@zsh.org>
Subject: Re: ${^var} and word splitting
Date: Mon, 24 Nov 2014 21:18:31 +0000	[thread overview]
Message-ID: <20141124211831.GA17829@chaz.gmail.com> (raw)
In-Reply-To: <20141124155524.0739b3ec__26419.4987401881$1416845250$gmane$org@pwslap01u.europe.root.pri>

2014-11-24 15:55:24 +0000, Peter Stephenson:
[...]
> Consequently it's easy to change the behaviour in the second case...
> This doesn't cause any test failures.  Unless anyone has any ideas why
> we do this, maybe we should simplify it like this?  If anyone does have
> ideas, we should write a test for that case.
[...]

I'd say no. People expect:

IFS=:
PATH=/bin::/usr/bin
setopt shwordsplit
set -- $PATH

to split $PATH into /bin, "" and /usr/bin. That's how all the
shells (except the Bourne shell) behave (and POSIX requires) and
is the whole point of having _IFS white space_ in the first
place.

(BTW, POSIX also requires :/bin::/usr/bin: to be split into "",
"/bin", "" and "/usr/bin" (not another "") as IFS is the
internal field _delimiter_ there, not _separator_. I tend to
prefer the zsh way (also yash's and older versions of pdksh)
though.)

What I don't like much is IFS white spaces (or x's with (s:x:))
to be collapsed *but not removed from head and tail*.

The whole point of having /IFS white spaces/ was to split
strings the /natural/ way (like words in a text, like awk's
fields or like the Bourne shell did for any character of $IFS,
not just the whitespace ones). That means considering sequences
of blanks as one *and* leading and trailing blanks not to create
fields. A string like " : foo : bar : : baz  " would be split
into "", foo, bar, "" and baz.

I don't see the point in doing one and not the other. IOW in:

~$ a=' a  b ' zsh -c 'print -l ${(s, ,)a}'
a
b
~$ a=' a  b ' zsh -c 'print -l "${(s, ,)a}"'

a
b

~$ a=' a  b ' zsh -c 'print -l "${(s, ,@)a}"'

a

b

~$


I'd rather 2 above behave either like 1 or 2. I'm fine with 1
and 3 behave like they do now.

It may be too late to change the behaviour now, though I'd find
it hard to imagine people relying on "$=var" to make empty
arguments at the beginning and end but not in the middle.

-- 
Stephane


  parent reply	other threads:[~2014-11-24 21:18 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
     [not found]     ` <20141124155524.0739b3ec__26419.4987401881$1416845250$gmane$org@pwslap01u.europe.root.pri>
2014-11-24 21:18       ` Stephane Chazelas [this message]
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=20141124211831.GA17829@chaz.gmail.com \
    --to=stephane.chazelas@gmail.com \
    --cc=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).