bug-bash
[Top][All Lists]
Advanced

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

Re: Heredoc with a multiline delimiter


From: Lawrence Velázquez
Subject: Re: Heredoc with a multiline delimiter
Date: Sun, 16 Mar 2025 14:47:19 -0400

On Sat, Mar 15, 2025, at 7:08 PM, MacBeth wrote:
> On Sat, Mar 15, 2025 at 12:33 PM Greg Wooledge <greg@wooledge.org> wrote:
>> On Sat, Mar 15, 2025 at 16:14:00 +0000, Nikola Novak via Bug reports for the 
>> GNU Bourne Again SHell wrote:
>> > How do you end the heredoc with a multiline delimiter such as the 
>> > following:
>> >
>> > cat << "a
>> > b"
>>
>> You don't.
>>
>
> However you could fake it, by including backslashes in the delimiter,
> which would allow literal newlines, but bash would ignore them as they
> are escape sequences. So they wouldn't actually be a part of the
> delimiter from bash's perspective, but merely visually and accepted
> from the literal input.
>
> $ cat <<EOT\
> $ EOF
> $ hello
> $ goodbye
> $ EOT\
> $ EOF
> hello
> goodbye
> $

This doesn't work when quoting part of the delimiter -- a common
thing to do.  In this case, one has to use the "true" delimiter,
which defeats the purpose.

        $ cat <<\EOT\
        $$ EOF
        $$ hello
        $$ goodbye
        $$ EOT\
        $$ EOF
        $$ \EOT\
        $$ EOF
        $$ oh no
        $$ EOTEOF
        hello
        goodbye
        EOT\
        EOF
        \EOT\
        EOF
        oh no
        $

-- 
vq



reply via email to

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