From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1838 invoked from network); 5 Nov 2008 22:49:45 -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.5 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; 5 Nov 2008 22:49:45 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 15191 invoked from network); 5 Nov 2008 22:49:37 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 5 Nov 2008 22:49:37 -0000 Received: (qmail 8885 invoked by alias); 5 Nov 2008 22:49:31 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 26011 Received: (qmail 8872 invoked from network); 5 Nov 2008 22:49:30 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 5 Nov 2008 22:49:30 -0000 Received: from mx.spodhuis.org (redoubt.spodhuis.org [193.202.115.177]) by bifrost.dotsrc.org (Postfix) with ESMTPS id B639F80308BE for ; Wed, 5 Nov 2008 23:49:26 +0100 (CET) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=d200807; d=spodhuis.org; h=Received:Date:From:To:Subject:Message-ID:Mail-Followup-To:References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; b=CmDRmkuU5GHi8f+0ihKPLTnvTnGaj+A72zUTx/ZqJDx4xH5kzya+FZfozjtrpLI5k9iCh6RLP0K6NJBKLN3ksNqMIk9Xw2AuX/Rk2MrVQA0be7X9VJo6mEK1BrA+zvACfDnNJbTI2IDEtDvGuM9k0lr+41aelSDL7fAJ8LbzNpo=; Received: by smtp.spodhuis.org with local id 1KxrBk-0002yp-Si; Wed, 05 Nov 2008 22:49:24 +0000 Date: Wed, 5 Nov 2008 14:49:24 -0800 From: Phil Pennock To: Zsh hackers list Subject: Re: f() { ...; } > file Message-ID: <20081105224924.GA11319@redoubt.spodhuis.org> Mail-Followup-To: Zsh hackers list References: <20081105212036.GA4698@sc.homeunix.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20081105212036.GA4698@sc.homeunix.net> X-Virus-Scanned: ClamAV 0.92.1/8577/Wed Nov 5 22:05:36 2008 on bifrost X-Virus-Status: Clean 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. % bash -c 'foo() { echo a >&3; } 3>&1; exec >/dev/null; foo' % bash -c 'foo() { echo a >&3; } 3>&1; foo' a % ksh -c 'foo() { echo a >&3; } 3>&1; foo' a % ksh -c 'foo() { echo a >&3; } 3>&1; exec >/dev/null; foo' % ksh -c 'echo $KSH_VERSION' @(#)PD KSH v5.2.14.2 99/07/13.2 % ksh93 -c 'foo() { echo a >&3; } 3>&1; exec >/dev/null; foo' % ksh93 -c 'foo() { echo a >&3; } 3>&1; foo' a % ksh93 -c 'echo $KSH_VERSION' Version M 93t 2008-07-25 Whereas zsh defers evaluating the file-descriptor: % zsh -c 'foo() { echo a >&3; } 3>&1; exec >/dev/null; foo 3>&2' a % (There might be a mistake in my analysis; collapsing into head-cold, mind fuzzy, not diagnosing the shell problem further).