From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27481 invoked by alias); 15 Apr 2015 19:57:59 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 34900 Received: (qmail 9710 invoked from network); 15 Apr 2015 19:57:55 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 X-Originating-IP: [80.3.228.158] X-Spam: 0 X-Authority: v=2.1 cv=dJgomYpb c=1 sm=1 tr=0 a=P+FLVI8RzFchTbbqTxIDRw==:117 a=P+FLVI8RzFchTbbqTxIDRw==:17 a=kj9zAlcOel0A:10 a=NLZqzBF-AAAA:8 a=q2GGsy2AAAAA:8 a=RqQ42g1PK10FVpM9pxcA:9 a=aHvcA1hyz11zjPH9:21 a=BXC7aXW9PkeC7PRe:21 a=CjuIK1q_8ugA:10 Date: Wed, 15 Apr 2015 20:52:18 +0100 From: Peter Stephenson To: zsh-workers@zsh.org Subject: Re: "var=value exec > file" ignores the assignment? Message-ID: <20150415205218.0483a1ec@ntlworld.com> In-Reply-To: References: <3D84EC4C-3267-4567-8642-B4F86AB93610@kba.biglobe.ne.jp> <150408101302.ZM23667@torch.brasslantern.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Fri, 10 Apr 2015 01:13:50 +0900 "Jun T." wrote: > 2015/04/09 02:13, Bart Schaefer wrote: > > > It's possible (likely?) your patch should add a POSIX_BUILTINS test. > > In the following case: > > x=$(command) exec > file > > we want to execute the 'command' unconditionally, but maybe do not want to > set the value of x if POSIX_BUILTINS is unset. > I wonder what is the easiest way (if any) to achieve this. This (based on the previous patch) might be good enough. It could probably do with a couple of tests. diff --git a/Src/exec.c b/Src/exec.c index 2ee37d0..2a8185c 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -3305,6 +3305,20 @@ execcmd(Estate state, int input, int output, int how, int last1) closemn(mfds, i, REDIR_CLOSE); if (nullexec) { + /* + * If nullexec is 2, we have variables to add with the redirections + * in place. If nullexec is 1, we may have variables but they + * need the standard restore logic. + */ + if (varspc) { + LinkList restorelist = 0, removelist = 0; + if (!isset(POSIXBUILTINS) && nullexec != 2) + save_params(state, varspc, &restorelist, &removelist); + addvars(state, varspc, 0); + if (restorelist) + restore_params(restorelist, removelist); + } + lastval = errflag ? errflag : cmdoutval; if (nullexec == 1) { /* * If nullexec is 1 we specifically *don't* restore the original @@ -3315,13 +3329,6 @@ execcmd(Estate state, int input, int output, int how, int last1) zclose(save[i]); goto done; } - /* - * If nullexec is 2, we have variables to add with the redirections - * in place. - */ - if (varspc) - addvars(state, varspc, 0); - lastval = errflag ? errflag : cmdoutval; if (isset(XTRACE)) { fputc('\n', xtrerr); fflush(xtrerr);