On 08/09/2021 08:15, Oğuz via austin-group-l at The Open Group wrote:
Sorry for butting in, but according to the standard, is there really a
syntax error in the following?
sh -c ': << do | for x in xxx
do
do echo $x
done'
busybox sh, dash, gwsh, netbsd sh, and freebsd sh complain about a
missing `done'.
This is not about 'do' as a delimiter, but about a heredoc right after
the items in a for command. This fails too:
sh -c ': << x | for x in xxx
x
do echo $x
done'
It results in an error about a missing 'do'. And this works, but should not:
sh -c ': << x | for x in xxx
do echo $x
x
done'
Only speaking for gwsh, but yes, I consider this is a bug and will make
sure to fix it. What's happening is a missing check for pending
heredocs, causing the heredoc to only start on line 3, rather than on
line 2 as it should. There is nothing that I am aware of in POSIX that
allows this.
Cheers,
Harald van Dijk