Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: read stdin in variable howto ?
- X-seq: zsh-users 9872
- From: Stephane Chazelas <Stephane_Chazelas@xxxxxxxx>
- To: zsh-users <zsh-users@xxxxxxxxxx>
- Subject: Re: read stdin in variable howto ?
- Date: Tue, 31 Jan 2006 14:51:15 +0000
- In-reply-to: <20060131134548.GA21082@xxxxxxxxxxxxxxxxxxxxxxx>
- Mail-followup-to: zsh-users <zsh-users@xxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <20060131092813.GA20363@xxxxxxxxxxxxxxxxxxxxxxx> <20060131120744.GF23308@xxxxxxxxxxxxxxxxxxx> <20060131120900.GG23308@xxxxxxxxxxxxxxxxxxx> <20060131134548.GA21082@xxxxxxxxxxxxxxxxxxxxxxx>
- Sender: Stephane Chazelas <stephane_chazelas@xxxxxxxx>
On Tue, Jan 31, 2006 at 02:45:48PM +0100, Marc Chantreux wrote:
> le 31/01/2006,
> Vincent Lefevre nous écrivait :
> > $(<&0) also works.
>
> exactly kind of answer i expected! thanks a lot Vincent!
[...]
But it does the same thing as $(cat) (it does call cat after a
pipe and a fork through the $NULLCMD mechanism), contrary to $(<
/dev/stdin) which uses the $(< file) special operator.
In $(<&0), it's command substitution, and $NULLCMD <&0. So the
shell forks a "cat" process whose stdout is set to a pipe. the
parent process reads the other end of the pipe to build the
string.
In $(< /dev/stdin), the shell reads the /dev/stdin file by
itself in the current process (no fork, no pipe). /dev/stdin (or
/dev/fd/0 or /proc/self/fd/0) is a special feature of some
operating systems, which on some systems (like Solaris) makes
that an open("/dev/stdin") is equivalent to a dup(0), and on
others (like Linux) opens the same resource as the one pointed
to by the fd 0 of the process (beware that some shells like bash
or ksh have a confusing feature where they emulate that OS
mechanism (well in the Solaris way) (in some circumstancies)).
Note that in both cases, the trailing empty lines are removed.
That's a bug/feature common to all the Bourne like shells.
--
Stéphane
Messages sorted by:
Reverse Date,
Date,
Thread,
Author