zsh-workers
 help / color / mirror / code / Atom feed
From: Martijn Dekker <martijn@inlv.org>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: [BUG] SHWORDSPLIT: unset IFS: $* and $@ don't split
Date: Sun, 19 Feb 2017 06:45:38 +0100	[thread overview]
Message-ID: <9196b7e6-2a81-37c1-c22a-e66754ea73a3@inlv.org> (raw)

In SHWORDSPLIT mode, if IFS is unset (meaning we expect default field
splitting),  unquoted $* and $@ (including in substitutions like
${1+$@}) or ${var-$*} do not perform the expected default field
splitting after generating fields from the positional parameters.

#! Src/zsh -f
setopt shwordsplit
set -- ab 'cd ef' gh
unset -v IFS
printf '[%s]\n' $* $@

Actual output:
[ab]
[cd ef]
[gh]
[ab]
[cd ef]
[gh]

Expected output:
[ab]
[cd]
[ef]
[gh]
[ab]
[cd]
[ef]
[gh]

Ref.:
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_05_02
For both $@ and $*, their behaviour is only different if they are
quoted. Unquoted, they behave identically:
| Expands to the positional parameters, starting from one, initially
| producing one field for each positional parameter that is set. When
| the expansion occurs in a context where field splitting will be
| performed, any empty fields may be discarded and each of the
| non-empty fields shall be further split as described in Field
| Splitting.

Note that it says "any empty fields *may* be discarded" (not "shall" be
discarded). Zsh discards them, as does nearly every other shell; yash as
of 2.44 is the only one I know of that doesn't. The description at
http://austingroupbugs.net/view.php?id=888 indicates the behaviour may
become mandatory in the future.

Thanks,

- M.


             reply	other threads:[~2017-02-19  5:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-19  5:45 Martijn Dekker [this message]
2017-02-20  0:49 ` Bart Schaefer

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=9196b7e6-2a81-37c1-c22a-e66754ea73a3@inlv.org \
    --to=martijn@inlv.org \
    --cc=zsh-workers@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).