From nobody  Sun May 10 12:52:46 1998
Received: (from nobody@localhost)
          by hub.freebsd.org (8.8.8/8.8.8) id MAA02340;
          Sun, 10 May 1998 12:52:46 -0700 (PDT)
          (envelope-from nobody)
Message-Id: <199805101952.MAA02340@hub.freebsd.org>
Date: Sun, 10 May 1998 12:52:46 -0700 (PDT)
From: iverok@sum.uio.no
To: freebsd-gnats-submit@freebsd.org
Subject: /bin/sh environment variables not set in simple commands
X-Send-Pr-Version: www-1.0

>Number:         6577
>Category:       bin
>Synopsis:       /bin/sh environment variables not set in simple commands
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun May 10 12:50:00 PDT 1998
>Closed-Date:    Mon May 15 14:33:50 MEST 2000
>Last-Modified:  Mon May 15 14:34:44 MEST 2000
>Originator:     Iver Odin Kvello
>Release:        2.2.5-RELEASE
>Organization:
>Environment:
FreeBSD faust.uio.no 2.2-RELEASE FreeBSD 2.2-RELEASE #0: Mon March 24
20:37:01 CET 1997 root@pcsum47.uio.no:/usr/src/sys/compile/BALLE i386
>Description:
Gambit-C version 3 depends upon
FOO=bar eval echo \$FOO
outputting "bar" to build. It outputs nothing. This is contrary to
the documented behaviour (for Simple Commands) and to observed
behaviour on AiX, Digital Unix and on bash.
>How-To-Repeat:
#!/bin/sh
FOO=ok eval echo \$FOO
>Fix:
substitute

FOO=bar ; eval expr \$FOO

or use bash.
>Release-Note:
>Audit-Trail:

From: woods@zeus.leitch.com (Greg A. Woods)
To: freebsd-gnats-submit@FreeBSD.ORG
Cc:  Subject: Re: bin/6577: /bin/sh environment variables not set in simple commands
Date: Tue, 12 May 1998 14:35:42 -0400 (EDT)

 [ On Sun, May 10, 1998 at 12:52:46 (-0700), iverok@sum.uio.no wrote: ]
 > Subject: bin/6577: /bin/sh environment variables not set in simple commands
 >
 > FOO=bar eval echo \$FOO
 > outputting "bar" to build. It outputs nothing. This is contrary to
 > the documented behaviour (for Simple Commands) and to observed
 > behaviour on AiX, Digital Unix and on bash.
 
 Just FYI, this works A-OK with PD KSH v5.2.13 97/10/27
 
 -- 
 							Greg A. Woods
 
 +1 416 443-1734      VE3TCP      <gwoods@acm.org>      <robohack!woods>
 Planix, Inc. <woods@planix.com>; Secrets of the Weird <woods@weird.com>
State-Changed-From-To: open->closed 
State-Changed-By: cracauer 
State-Changed-When: Thu Sep 17 00:07:13 MEST 1998 
State-Changed-Why:  
Fixed by Tor Egge in -current. 
State-Changed-From-To: closed->open 
State-Changed-By: cracauer 
State-Changed-When: Thu Sep 17 11:14:00 MEST 1998 
State-Changed-Why:  
I'm sorry, it seemed to work yesterday due to loosy cut'n'paste of 
mine. 

This isn't fixed.Pointed out by Tor Egge. 

From: Anatoly Vorobey <mellon@pobox.com>
To: freebsd-gnats-submit@freebsd.org
Cc:  
Subject: Re: bin/6577: /bin/sh environment variables not set in simple commands
Date: Thu, 20 Apr 2000 09:27:28 +0000

 >Gambit-C version 3 depends upon
 >FOO=bar eval echo \$FOO
 >outputting "bar" to build. It outputs nothing. This is contrary to
 >the documented behaviour (for Simple Commands) and to observed
 >behaviour on AiX, Digital Unix and on bash.
 
 I have a fix for this. It's a "I know what I'm doing" fix rather than
 "this seems to work" fix; so here's a bit of explanation
 which hopefully will make it easier for someone to review and commit ;)
 
 Basically, our sh(1) keeps internal environment, defined by FOO=bar pairs
 before the command, pointed to by variable cmdenviron defined in eval.c . 
 It merges it with the global environment only when executing external
 commands. The builtin commands, on the other hands, are expected to use
 bltinlookup() which will look both into cmdenviron and the global
 environment, instead of vanilla lookupvar() which only looks into the latter.
 
 The simple builtin commands which are affected by variables all do that
 (a good example is 'cd' checking $HOME). However, "eval" itself is 
 implemented as a builtin command, which will call evalstr -- the "real"
 eval used also by the command loop. When this "real" eval which parses
 and executes all commands needs to look into a variable, it happens in
 codepath evalstr->evalcommand->expandarg->argstr->evalvar->lookupvar.
 Because of this last lookupvar() call, the builtin eval effectively
 ignores its internal environment, even though it's there in "cmdenviron"
 while it executes. I have changed that call from lookupvar() to bltinlookup().
 Since the whole codepath basically only ever comes from inside eval 
 processing, it's okay as we do want eval to always remember about internal
 environment just in case it's being executed as a builtin.
 
 An additional gotcha is that earlier evalcommand() never bothered to
 clear cmdenviron, and it could hold internal environment of some builtin
 command long after it's done executing, which was okay since all builtin
 commands were executed from evalcommand() and it would reset cmdenviron
 before launching one. This is no more acceptable since now evalcommand()
 will consult cmdenviron just to parse its arguments, and when this
 evalcommand() does *not* execute as a result of a builtin call, cmdenviron
 may contain remains of a previous builtin's environment. Thus I clear
 cmdenviron upon a builtin's exit now.
 
 Testing: well, I've played with it. I've tested that things like
 FOO=bar eval echo \$FOO now work correctly. I've built a few worlds.
 I've run a few configures.
 
 Index: eval.c
 ===================================================================
 RCS file: /freebsd/cvs/src/bin/sh/eval.c,v
 retrieving revision 1.27
 diff -u -r1.27 eval.c
 --- eval.c	1999/12/20 13:42:59	1.27
 +++ eval.c	2000/04/20 08:45:47
 @@ -850,6 +850,7 @@
  		exitstatus = (*builtinfunc[cmdentry.u.index])(argc, argv);
  		flushall();
  cmddone:
 +		cmdenviron = NULL;
  		out1 = &output;
  		out2 = &errout;
  		freestdout();
 Index: expand.c
 ===================================================================
 RCS file: /freebsd/cvs/src/bin/sh/expand.c,v
 retrieving revision 1.31
 diff -u -r1.31 expand.c
 --- expand.c	1999/12/15 11:46:32	1.31
 +++ expand.c	2000/04/20 08:47:23
 @@ -667,7 +667,7 @@
  		set = varisset(var, varflags & VSNUL);
  		val = NULL;
  	} else {
 -		val = lookupvar(var);
 +		val = bltinlookup(var, 1);
  		if (val == NULL || ((varflags & VSNUL) && val[0] == '\0')) {
  			val = NULL;
  			set = 0;
 
 -- 
 Anatoly Vorobey,
 mellon@pobox.com http://pobox.com/~mellon/
 "Angels can fly because they take themselves lightly" - G.K.Chesterton
 
State-Changed-From-To: open->closed 
State-Changed-By: cracauer 
State-Changed-When: Mon May 15 14:33:50 MEST 2000 
State-Changed-Why:  
Fixed in -current.  Thanks to Anatoly Vorobey <mellon@pobox.com> for 
the fix.  Will be merged into 4-stable before 4.1 
>Unformatted:
