zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@ibmth.df.unipi.it>
To: zsh-workers@math.gatech.edu
Subject: PATCH: 3.1.5: eval with exported vars
Date: Fri, 11 Dec 1998 10:52:46 +0100	[thread overview]
Message-ID: <9812110952.AA23579@ibmth.df.unipi.it> (raw)
In-Reply-To: "Phil Pennock"'s message of "Fri, 11 Dec 1998 08:05:58 NFT." <19981211080558.46630@athenaeum.demon.co.uk>

Phil Pennock wrote:
> Trying this:
> % FOO=x eval sh -c 'echo $FOO'
> and then without the eval, it seems the eval loses the auto-export
> functionality, in both 3.0.5 and 3.1.5.  It doesn't appear to be
> documented though.

The workaround is

eval 'FOO=x sh -c '\'echo $FOO'\'

by the way.  (Note all the quotes:  see below.)

> Bug?

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 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.

There's something that had me horribly confused (though it's actually
working the way God intended):

% FOO=x eval sh -c 'echo $FOO'
<nothing printed>

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

phew.

*** Src/exec.c.eval	Thu Dec 10 11:24:46 1998
--- Src/exec.c	Fri Dec 11 10:14:01 1998
***************
*** 1792,1800 ****
  
  	    if (cmd->vars) {
  		/* Export this if the command is a shell function,
! 		 * but not if it's a builtin.
  		 */
! 		addvars(cmd->vars, is_shfunc);
  		if (errflag) {
  		    restore_params(restorelist, removelist);
  		    lastval = 1;
--- 1792,1802 ----
  
  	    if (cmd->vars) {
  		/* Export this if the command is a shell function,
! 		 * but not if it's a builtin, unless the builtin
! 		 * is an eval.
  		 */
! 		addvars(cmd->vars, is_shfunc ||
! 			(is_builtin && ((Builtin)hn)->funcid == BIN_EVAL));
  		if (errflag) {
  		    restore_params(restorelist, removelist);
  		    lastval = 1;



Peter Stephenson <pws@ibmth.df.unipi.it>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarroti 2, 56127 Pisa, Italy


       reply	other threads:[~1998-12-11 10:11 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <19981211080558.46630@athenaeum.demon.co.uk>
1998-12-11  9:52 ` Peter Stephenson [this message]
1998-12-11 12:23   ` Andrej Borsenkow
1998-12-11 12:45     ` Peter Stephenson
1998-12-11 13:27       ` Andrej Borsenkow

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9812110952.AA23579@ibmth.df.unipi.it \
    --to=pws@ibmth.df.unipi.it \
    --cc=zsh-workers@math.gatech.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).