[Top][All Lists]

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

Re: [Help-bash] How to let a command take multiple here-doc?

From: Peng Yu
Subject: Re: [Help-bash] How to let a command take multiple here-doc?
Date: Sun, 31 May 2015 19:38:29 -0500

How to understand why the following code only print b?

cat <<EOF1 <<EOF2

It is not clear what the correct output should be based on POSIX.

Also, the above link shows the following example. I am not sure why it
is usefully to intertwine the heredocs of the two separate commands.
Does anybody know?

cat <<eof1; cat <<eof2

On Fri, May 29, 2015 at 7:29 AM, Eric Blake <address@hidden> wrote:
> On 05/28/2015 09:34 PM, Dave Rutherford wrote:
>> On Thu, May 28, 2015 at 11:23 PM, Peng Yu <address@hidden> wrote:
>>> The following bash code uses cat twice. Because one uses EOF the other
>>> uses 'EOF', they can not readily be combined.
>>> x='Hello World!'
>>> cat <<EOF
>>> $x
>>> EOF
>>> cat <<'EOF'
>>> $x
>>> EOF
>> This works as expected. What behavior are you looking for?
>>> I can't find that that bash support multiple here-docs for the same
>>> command. Is it so?
>> You mean one cat with two here-documents? You can't do that,
>> there's only one stdin.
> On systems with /dev/fd, you can do:
> $ cat - /dev/fd/4 <<EOF 4<<EOF
>> a
>> EOF
>> b
>> EOF
> a
> b
> for a single cat process that reads from two different fds.  But it's
> such an unusual idiom that I don't recommend it for code trying to be
> portable.
> --
> Eric Blake   eblake redhat com    +1-919-301-3266
> Libvirt virtualization library


reply via email to

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