Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[BUG] SHWORDSPLIT: unset IFS: $* and $@ don't split



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