bug-bash
[Top][All Lists]
Advanced

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

Re: here document and STDIN


From: Cai Qian
Subject: Re: here document and STDIN
Date: Tue, 23 May 2006 19:08:50 +0100

The information is helpful. The problem by using

perl -e '
   XXXXX
'

is that there seems no way to using single quota in Perl code any more.

On 5/23/06, Paul Jarc <prj@po.cwru.edu> wrote:
"Cai Qian" <loricai@gmail.com> wrote:
> For following code,
>
> sh <<EOF
>       read
> EOF
>
> I have no idea why will not block.

The "read" command reads from the shell's stdin, which is the here
document.  At the point where the "read" command is executed, the
shell has already read the "read" command from the here document, so
the next thing read from there will be end-of-file.  If you want the
"read" command to read from the original stdin that was present before
the here document was introduced, you can copy it to another
descriptor:

sh <<EOF 3<&0
    read <&3
EOF

> So I can run some Perl code inside like,
>
> perl - <<'EOF'
>      XXXXX
>
> EOF

With perl, it may be easier to use -e instead of a here document:
perl -e '
    XXXXX
'

Then perl will still be connected to the original stdin, without any
need for duplicating descriptors.


paul





reply via email to

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