help-bash
[Top][All Lists]
Advanced

[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: Eric Blake
Subject: Re: [Help-bash] How to let a command take multiple here-doc?
Date: Fri, 29 May 2015 06:29:27 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0

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 http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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