sh: Allow a newline before "in" in a for command, as required by POSIX.

This commit is contained in:
Jilles Tjoelker 2009-11-14 22:08:32 +00:00
parent 1f1158b28d
commit 7ab07e8ada
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=199282
2 changed files with 32 additions and 1 deletions

View File

@ -364,7 +364,9 @@ TRACE(("expecting DO got %s %s\n", tokname[got], got == TWORD ? wordtext : ""));
n1 = (union node *)stalloc(sizeof (struct nfor));
n1->type = NFOR;
n1->nfor.var = wordtext;
if (readtoken() == TWORD && ! quoteflag && equal(wordtext, "in")) {
while (readtoken() == TNL)
;
if (lasttoken == TWORD && ! quoteflag && equal(wordtext, "in")) {
app = ≈
while (readtoken() == TWORD) {
n2 = (union node *)stalloc(sizeof (struct narg));

View File

@ -0,0 +1,29 @@
# $FreeBSD$
nl='
'
list=' a b c'
for s1 in "$nl" " "; do
for s2 in "$nl" ";"; do
for s3 in "$nl" " "; do
r=''
eval "for i${s1}in ${list}${s2}do${s3}r=\"\$r \$i\"; done"
[ "$r" = "$list" ] || exit 1
done
done
done
set -- $list
for s2 in "$nl" " " ";"; do # s2=";" is an extension to POSIX
for s3 in "$nl" " "; do
r=''
eval "for i${s2}do${s3}r=\"\$r \$i\"; done"
[ "$r" = "$list" ] || exit 1
done
done
for s1 in "$nl" " "; do
for s2 in "$nl" ";"; do
for s3 in "$nl" " "; do
eval "for i${s1}in${s2}do${s3}exit 1; done"
done
done
done