[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Follow-up to Non-expanding here-documents inside command substitutio

From: Chet Ramey
Subject: Re: Follow-up to Non-expanding here-documents inside command substitution
Date: Fri, 24 Feb 2017 09:38:06 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:45.0) Gecko/20100101 Thunderbird/45.7.1

On 2/24/17 12:14 AM, Kevin Grigorenko wrote:
> On February 11th 2017, there was a discussion on the topic of
> "Non-expanding here-documents inside command substitution are subject to
> newline joining" where it was confirmed that Bash contains a bug. Two
> questions:
> 1. Is there a plan to fix this or should a patch be submitted?
> 2. Regarding the response:
>> [POSIX] is not necessarily ambiguous, but it does require close
>> reading.
> Can you please explain how it was concluded that it's a bug based on the
> specification?

OK.  The command substitution is a red herring; it's relevant only in that
it pointed out where the bug was.

The delimiter to the here-document is quoted, so the lines are not
expanded. In this case, the shell reads lines from the input as if they
were quoted. If a backslash appears in a context where it is quoted, it
does not act as an escape character (see below), and the special handling
of backslash-newline does not take place. In fact, if any part of the
delimiter is quoted, the here-document lines are read as if single-quoted.

The text in Posix 2.2.1 is written awkwardly, but means that the backslash
is only treated specially when it's not quoted.  You can quote a backslash
and inhibit all all expansion only with single quotes or another backslash.

The close reading part is the "not expanded" text implying the single
quotes. The standard says in 2.2 that here documents are "another form of
quoting," but the only form of quoting in which words are not expanded at
all is single quotes.  So it's a form of quoting that is just about
exactly like single quotes, but not single quotes.

``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/

reply via email to

[Prev in Thread] Current Thread [Next in Thread]