From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6944 invoked from network); 13 Nov 2008 14:42:26 -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; 13 Nov 2008 14:42:26 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 9140 invoked from network); 13 Nov 2008 14:42:22 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 13 Nov 2008 14:42:22 -0000 Received: (qmail 10646 invoked by alias); 13 Nov 2008 14:42:17 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 26036 Received: (qmail 10636 invoked from network); 13 Nov 2008 14:42:16 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 13 Nov 2008 14:42:16 -0000 Received: from mail.o2.co.uk (jabba.london.02.net [82.132.130.169]) by bifrost.dotsrc.org (Postfix) with ESMTP id 7DA3080308BE for ; Thu, 13 Nov 2008 15:42:13 +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 49196F1C005E84EC for zsh-workers@sunsite.dk; Thu, 13 Nov 2008 14:46:12 +0000 Received: from chazelas by sc.homeunix.net with local (Exim 4.69) (envelope-from ) id 1L0dOe-0002NK-7U for zsh-workers@sunsite.dk; Thu, 13 Nov 2008 14:42:12 +0000 Date: Thu, 13 Nov 2008 14:42:12 +0000 From: Stephane Chazelas To: Zsh hackers list Subject: [PATCH] Re: f() { ...; } > file Message-ID: <20081113144212.GB5114@sc.homeunix.net> Mail-Followup-To: Zsh hackers list References: <20081105212036.GA4698@sc.homeunix.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20081105212036.GA4698@sc.homeunix.net> User-Agent: Mutt/1.5.16 (2007-09-19) X-Virus-Scanned: ClamAV 0.92.1/8627/Thu Nov 13 10:42:40 2008 on bifrost X-Virus-Status: Clean On Wed, Nov 05, 2008 at 09:20:36PM +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. > > It's OK when declaring the function as > > foo() echo a > file > or > foo() (echo a) > file > > instead of > > foo() { echo a; } > file [...] The patch below seems to fix it. It just removes the special case of f() { }. I don't why it was there in the first place. rev 1.1 of parse.c already had it. Not sure how many things this patch would break ;) Index: Src/parse.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/parse.c,v retrieving revision 1.76 diff -p -u -r1.76 parse.c --- Src/parse.c 29 Sep 2008 08:46:33 -0000 1.76 +++ Src/parse.c 13 Nov 2008 14:31:10 -0000 @@ -1685,34 +1685,20 @@ par_simple(int *complex, int nr) onp = ecnpats; ecnpats = 0; - if (tok == INBRACE) { - int c = 0; + int ll, sl, pl, c = 0; - yylex(); - par_list(&c); - if (tok != OUTBRACE) { - cmdpop(); - lineno += oldlineno; - ecnpats = onp; - ecssub = oecssub; - YYERROR(oecused); - } - yylex(); - } else { - int ll, sl, pl, c = 0; - - ll = ecadd(0); - sl = ecadd(0); - pl = ecadd(WCB_PIPE(WC_PIPE_END, 0)); - - if (!par_cmd(&c)) { - cmdpop(); - YYERROR(oecused); - } - - set_sublist_code(sl, WC_SUBLIST_END, 0, ecused - 1 - sl, c); - set_list_code(ll, (Z_SYNC | Z_END), c); + ll = ecadd(0); + sl = ecadd(0); + pl = ecadd(WCB_PIPE(WC_PIPE_END, 0)); + + if (!par_cmd(&c)) { + cmdpop(); + YYERROR(oecused); } + + set_sublist_code(sl, WC_SUBLIST_END, 0, ecused - 1 - sl, c); + set_list_code(ll, (Z_SYNC | Z_END), c); + cmdpop(); ecadd(WCB_END()); -- Stéphane