Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
[BUG] SHWORDSPLIT: unset IFS: $* and $@ don't split
- X-seq: zsh-workers 40578
- From: Martijn Dekker <martijn@xxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: [BUG] SHWORDSPLIT: unset IFS: $* and $@ don't split
- Date: Sun, 19 Feb 2017 06:45:38 +0100
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
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.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author