[Top][All Lists]

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

Re: Non-expanding here-documents inside command substitution are subject

From: Chet Ramey
Subject: Re: Non-expanding here-documents inside command substitution are subject to newline joining
Date: Sat, 11 Feb 2017 17:19:01 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:45.0) Gecko/20100101 Thunderbird/45.7.1

On 2/11/17 12:11 AM, Michael Homer wrote:

> If the same command is put inside command substitution instead, Bash (and 
> pdksh) behaves differently than the others, and performs newline joining to 
> have a single line in the middle “def ghi”. Given
>     x=$(cat <<'EOT'
>     abc
>     def \
>     ghi
>     jkl
>     EOT
>     )
> In Bash, x now contains:
>     abc\ndef ghi\njkl

Thanks for the report.  This is a bug in bash's command substitution parsing.

> POSIX isn’t perfectly unambiguous here, but my intuition reading it is 
> consistent with everyone else’s behaviour rather than Bash’s. The relevant 
> parts of the specification I could find and more detail are given in 
> <http://unix.stackexchange.com/q/340923/73093>, and the original motivating 
> example was from someone trying to produce ASCII art inside command 
> substitution in an earlier question 
> <http://unix.stackexchange.com/q/340718/73093>.

It is not necessarily ambiguous, but it does require close reading.

> Geir Hauge in the comments of the question provided this patch to parse.y 
> purporting to solve the issue: <http://sprunge.us/ZMAT>. 

That's a good fix.

``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]