* [BUG] SHWORDSPLIT: unset IFS: $* and $@ don't split
@ 2017-02-19 5:45 Martijn Dekker
2017-02-20 0:49 ` Bart Schaefer
0 siblings, 1 reply; 2+ messages in thread
From: Martijn Dekker @ 2017-02-19 5:45 UTC (permalink / raw)
To: Zsh hackers list
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.
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [BUG] SHWORDSPLIT: unset IFS: $* and $@ don't split
2017-02-19 5:45 [BUG] SHWORDSPLIT: unset IFS: $* and $@ don't split Martijn Dekker
@ 2017-02-20 0:49 ` Bart Schaefer
0 siblings, 0 replies; 2+ messages in thread
From: Bart Schaefer @ 2017-02-20 0:49 UTC (permalink / raw)
To: Martijn Dekker, Zsh hackers list
On Feb 19, 6:45am, Martijn Dekker wrote:
} Subject: [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.
This one turns out to be more tractible.
diff --git a/Src/subst.c b/Src/subst.c
index 670f3f0..1c2397c 100644
--- a/Src/subst.c
+++ b/Src/subst.c
@@ -3476,7 +3476,8 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags,
val = sepjoin(aval, sep, 1);
isarr = 0;
ms_flags = 0;
- } else if (force_split && (spsep || nojoin == 2)) {
+ } else if (force_split &&
+ (spsep || nojoin == 2 || (!ifs && isarr < 0))) {
/* Hack to simulate splitting individual elements:
* forced joining as previously determined, or
* join on what we later use to forcibly split
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-02-20 0:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-19 5:45 [BUG] SHWORDSPLIT: unset IFS: $* and $@ don't split Martijn Dekker
2017-02-20 0:49 ` Bart Schaefer
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).