From: Eric Blake <eblake@redhat.com>
To: Oleg Bulatov <oleg@bulatov.me>,
dash@vger.kernel.org, Austin Group <austin-group-l@opengroup.org>
Subject: Re: heredoc and subshell
Date: Tue, 23 Feb 2016 16:16:38 -0700 [thread overview]
Message-ID: <56CCE856.1050502@redhat.com> (raw)
In-Reply-To: <56CCE1E3.1060805@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 1975 bytes --]
On 02/23/2016 03:49 PM, Eric Blake wrote:
> [adding the Austin Group]
>
> On 02/23/2016 03:07 PM, Oleg Bulatov wrote:
>> Hello,
>>
>> trying to minimize a shell code I found an unobvious moment with heredocs and subshells.
>
> Thanks for a cool testcase.
>
>>
>> Is it specified by POSIX how next code should be parsed? dash output for this code differs from bash and zsh.
>
> XCU 2.3 says:
>
> When an io_here token has been recognized by the grammar (see Shell
> Grammar), one or more of the subsequent lines immediately following the
> next NEWLINE token form the body of one or more here-documents and shall
> be parsed according to the rules of Here-Document.
>
> and 2.7.4 says:
>
> The here-document shall be treated as a single word that begins after
> the next <newline> and continues until there is a line containing only
> the delimiter and a <newline>, with no <blank> characters in between.
> Then the next here-document starts, if there is one.
>
> but with no mention of what happens if you somehow manage to make the
> next <newline> be part of an incomplete shell word on the line
> containing the here-doc operator.
As it is, all shells I tested have a shorter test case that proves they
don't always start looking for the heredoc body after the first newline:
$ dash -c 'cat <<ONE && cat \''
<<TWO
a
ONE
b
TWO
'
a
b
The newline immediately after the backslash is NOT used to start the
first heredoc.
> Maybe we need a defect against the standard that says behavior is
> unspecified if the next <newline> after a here-doc operator occurs in
> the middle of a shell word.
Or maybe refine the wording to state the first unescaped newline, since
backslash escaping seems to consistently work (and only newlines inside
incomplete command substitution is where the confusion begins).
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
next prev parent reply other threads:[~2016-02-23 23:16 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-23 22:07 heredoc and subshell Oleg Bulatov
2016-02-23 22:49 ` Eric Blake
2016-02-23 23:16 ` Eric Blake [this message]
[not found] ` <56CCE1E3.1060805-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2016-02-24 10:58 ` Joerg Schilling
[not found] ` <56cd8cd1.LdVYbpfe+0tQMm8I%Joerg.Schilling-8LS2qeF34IpklNlQbfROjRvVK+yQ3ZXh@public.gmane.org>
2016-02-24 12:27 ` Shware Systems
2016-02-24 12:32 ` Joerg Schilling
2016-02-24 20:27 ` Oleg Bulatov
2016-02-23 23:18 ` Jilles Tjoelker
2016-02-24 8:46 ` Thorsten Glaser
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=56CCE856.1050502@redhat.com \
--to=eblake@redhat.com \
--cc=austin-group-l@opengroup.org \
--cc=dash@vger.kernel.org \
--cc=oleg@bulatov.me \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox