From: Stephane Chazelas <Stephane_Chazelas@yahoo.fr>
To: zsh-users <zsh-users@sunsite.dk>
Subject: Re: read stdin in variable howto ?
Date: Tue, 31 Jan 2006 14:51:15 +0000 [thread overview]
Message-ID: <20060131145115.GA4973@sc> (raw)
In-Reply-To: <20060131134548.GA21082@xpeerience.u-strasbg.fr>
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
next prev parent reply other threads:[~2006-01-31 14:51 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-01-31 9:28 Marc Chantreux
[not found] ` <ef88cc6b0601310206w26e9a277o5ad42bda342c795a@mail.gmail.com>
2006-01-31 10:11 ` Marc Chantreux
2006-01-31 10:36 ` Artur Penttinen
2006-01-31 11:09 ` Marc Chantreux
2006-01-31 12:07 ` Vincent Lefevre
2006-01-31 12:09 ` Vincent Lefevre
2006-01-31 13:45 ` Marc Chantreux
2006-01-31 14:51 ` Stephane Chazelas [this message]
2006-01-31 21:10 ` Marc Chantreux
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20060131145115.GA4973@sc \
--to=stephane_chazelas@yahoo.fr \
--cc=zsh-users@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).