[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: here document and STDIN
From: |
Paul Jarc |
Subject: |
Re: here document and STDIN |
Date: |
Tue, 23 May 2006 13:41:11 -0400 |
User-agent: |
Gnus/5.110003 (No Gnus v0.3) Emacs/21.4 (gnu/linux) |
"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