MFC r199282: sh: Allow a newline before "in" in a for command,

as required by POSIX.
This commit is contained in:
jilles 2010-04-20 22:20:31 +00:00
parent e24a574792
commit 754430692e
2 changed files with 32 additions and 1 deletions

View File

@ -365,7 +365,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