From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12672 invoked from network); 6 Nov 2008 14:39:01 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.5 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 6 Nov 2008 14:39:01 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 73078 invoked from network); 6 Nov 2008 14:38:54 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 6 Nov 2008 14:38:54 -0000 Received: (qmail 18114 invoked by alias); 6 Nov 2008 14:38:47 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 26015 Received: (qmail 18102 invoked from network); 6 Nov 2008 14:38:47 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 6 Nov 2008 14:38:47 -0000 Received: from mail.o2.co.uk (yoda.london.02.net [82.132.130.151]) by bifrost.dotsrc.org (Postfix) with ESMTP id B3FF980308BE for ; Thu, 6 Nov 2008 15:38:41 +0100 (CET) Received: from sc.homeunix.net (78.105.216.138) by mail.o2.co.uk (8.0.013.3) (authenticated as stephane.chazelas) id 491095A3009423A5 for zsh-workers@sunsite.dk; Thu, 6 Nov 2008 14:38:41 +0000 Received: from chazelas by sc.homeunix.net with local (Exim 4.69) (envelope-from ) id 1Ky60O-0001Yb-Fc for zsh-workers@sunsite.dk; Thu, 06 Nov 2008 14:38:40 +0000 Date: Thu, 6 Nov 2008 14:38:40 +0000 From: Stephane Chazelas To: Zsh hackers list Subject: Re: f() { ...; } > file Message-ID: <20081106143840.GA5679@sc.homeunix.net> Mail-Followup-To: Zsh hackers list References: <20081105212036.GA4698@sc.homeunix.net> <20081105224924.GA11319@redoubt.spodhuis.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20081105224924.GA11319@redoubt.spodhuis.org> User-Agent: Mutt/1.5.16 (2007-09-19) X-Virus-Scanned: ClamAV 0.92.1/8580/Thu Nov 6 06:39:41 2008 on bifrost X-Virus-Status: Clean On Wed, Nov 05, 2008 at 02:49:24PM -0800, Phil Pennock wrote: > On 2008-11-05 at 21:20 +0000, Stephane Chazelas wrote: > > $ bash -c 'foo() { echo a >&3; } 3>&1; foo' > > a > > $ ksh -c 'foo() { echo a >&3; } 3>&1; foo' > > a > > $ zsh -c 'foo() { echo a >&3; } 3>&1; foo' > > foo: 3: bad file descriptor > > $ ARGV0=sh zsh -c 'foo() { command echo a >&3; } 3>&1; foo' > > foo: 3: bad file descriptor > > > > It looks like zsh evaluates the redirection at the time the > > function is defined rather than when it is called. > > Back to front. > > I think that you're misunderstanding what bash et al are doing. They're > not deferring the redirection, they're resolving the redirection at > definition time so that it remains bound to stdout. hi Phil, no, there're not. If that were true (and if I understand correctly what you're saying), bash -c 'f() { :; } 3>&1; echo foo >&3' would output foo on stdout. defining a function foo is sticking foo() in front of a statement. That has been like that since functions have been implemented in the Bourne shell. So foo() echo bar > baz is defining a function foo that does "echo bar > baz". All the shells are doing that, except zsh and only if the statement is of the form { ...; } (there might be other cases). > > % bash -c 'foo() { echo a >&3; } 3>&1; exec >/dev/null; foo' Yes. It's as if you had run: bash -c 'exec >/dev/null; { echo a >&3; } 3>&1' My understanding is that for some reason, % zsh -c 'foo() { echo a >&3; } 3>&1; exec >/dev/null; foo' Is as if you had run: % zsh -c '3>&1; exec >/dev/null; { echo a >&3; }' -- Stéphane