From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3602 invoked from network); 11 Dec 1998 12:27:29 -0000 Received: from math.gatech.edu (list@130.207.146.50) by ns1.primenet.com.au with SMTP; 11 Dec 1998 12:27:29 -0000 Received: (from list@localhost) by math.gatech.edu (8.9.1/8.9.1) id HAA06802; Fri, 11 Dec 1998 07:25:05 -0500 (EST) Resent-Date: Fri, 11 Dec 1998 07:25:05 -0500 (EST) From: "Andrej Borsenkow" To: "Peter Stephenson" , Subject: RE: PATCH: 3.1.5: eval with exported vars Date: Fri, 11 Dec 1998 15:23:11 +0300 Message-ID: <001801be2501$04976be0$21c9ca95@mowp.siemens.ru> MIME-Version: 1.0 Content-Type: text/plain; charset="koi8-r" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook 8.5, Build 4.71.2173.0 In-Reply-To: <9812110952.AA23579@ibmth.df.unipi.it> Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V5.00.0810.800 Resent-Message-ID: <"Drvjx1.0.Dg1.XyGSs"@math> Resent-From: zsh-workers@math.gatech.edu X-Mailing-List: archive/latest/4749 X-Loop: zsh-workers@math.gatech.edu Precedence: list Resent-Sender: zsh-workers-request@math.gatech.edu > > I was going to say yes, but it's specifically mentioned in the source > that it does this (exec.c, line 1793 of my current version): > > if (cmd->vars) { > /* Export this if the command is a shell function, > * but not if it's a builtin. > */ > addvars(cmd->vars, is_shfunc); > I just checked it with two versions of sh and ksh and all behave the same way as zsh. I think, it is also correct. Variable assignment does no _export_ them. It makes them available in execution environment of command to be executed. It is just, that if command executes in separate process, the only way to make them available is to export them ... In case of eval, FOO is set, but not exported, which is correct - and hence, spawned process does not see it. But zsh takes one thing wrong. Variable assignment made before special builtins, remain in effect after builtin finishes (see POSIX and Single Unix and Unix 98). eval is special builtin, but see bor@itsrm2:/tools/var%> FOO=x eval 'echo $FOO' x bor@itsrm2:/tools/var%> echo $FOO But as I understand, your patch blindly exports variable for every builtin? > I think the idea must have been that `builtins don't need values > exported' which, as you've seen, is not true in this case. The patch > is the simplest fix, and I think it's good enough. > Again, FOO=x cmd does not export it at all. something strange here. > There's something that had me horribly confused (though it's actually > working the way God intended): > > % FOO=x eval sh -c 'echo $FOO' > > > That's because eval sees the string "sh -c echo $FOO" and turns this > into sh -c 'echo' 'x', so sh gets an 'echo' command with $0 set to x. > To prove it: > > % FOO=x eval sh -c '"echo \$0" $FOO' > x > > (why $0 not $1?) so you really need > > % FOO=x eval sh -c \''echo $FOO'\' > x Wow! May wonders never cease :) bor@itsrm2:/tools/var%> FOO=x eval sh -c '"echo $FOO"' x bor@itsrm2:/tools/var%> echo $FOO bor@itsrm2:/tools/var%> Still wrong - FOO disappears.