From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17904 invoked from network); 31 Jan 2006 14:51:36 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.0 (2005-09-13) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00, FORGED_RCVD_HELO autolearn=ham version=3.1.0 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 31 Jan 2006 14:51:36 -0000 Received: (qmail 44540 invoked from network); 31 Jan 2006 14:51:28 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 31 Jan 2006 14:51:28 -0000 Received: (qmail 572 invoked by alias); 31 Jan 2006 14:51:20 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 9872 Received: (qmail 542 invoked from network); 31 Jan 2006 14:51:20 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 31 Jan 2006 14:51:20 -0000 Received: (qmail 43482 invoked from network); 31 Jan 2006 14:51:20 -0000 Received: from smtpout0143.sc1.cp.net (HELO n066.sc1.cp.net) (64.97.136.143) by a.mx.sunsite.dk with SMTP; 31 Jan 2006 14:51:19 -0000 Received: from sc (82.26.175.92) by n066.sc1.cp.net (7.2.069.1) id 43C54FAD00231845 for zsh-users@sunsite.dk; Tue, 31 Jan 2006 14:51:17 +0000 Received: from chazelas by sc with local (Exim 3.36 #1 (Debian)) id 1F3wqh-0002uy-00 for ; Tue, 31 Jan 2006 14:51:15 +0000 Date: Tue, 31 Jan 2006 14:51:15 +0000 From: Stephane Chazelas To: zsh-users Subject: Re: read stdin in variable howto ? Message-ID: <20060131145115.GA4973@sc> Mail-Followup-To: zsh-users References: <20060131092813.GA20363@xpeerience.u-strasbg.fr> <20060131120744.GF23308@prunille.vinc17.org> <20060131120900.GG23308@prunille.vinc17.org> <20060131134548.GA21082@xpeerience.u-strasbg.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20060131134548.GA21082@xpeerience.u-strasbg.fr> User-Agent: Mutt/1.5.6i Sender: Stephane Chazelas 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