From mark@grumble.grondar.za  Sat Feb 17 10:56:32 1996
Received: from grumble.grondar.za (root@grumble.grondar.za [196.7.18.130])
          by freefall.freebsd.org (8.7.3/8.7.3) with ESMTP id KAA23054
          for <FreeBSD-gnats-submit@freebsd.org>; Sat, 17 Feb 1996 10:56:23 -0800 (PST)
Received: (from mark@localhost) by grumble.grondar.za (8.7.3/8.7.3) id UAA13002; Sat, 17 Feb 1996 20:56:16 +0200 (SAT)
Message-Id: <199602171856.UAA13002@grumble.grondar.za>
Date: Sat, 17 Feb 1996 20:56:16 +0200 (SAT)
From: Mark Murray <mark@grondar.za>
Reply-To: mark@grondar.za
To: FreeBSD-gnats-submit@freebsd.org
Subject: /bin/sh does not pass environment variables on properly
X-Send-Pr-Version: 3.2

>Number:         1030
>Category:       bin
>Synopsis:       /bin/sh does not pass environment variables on properly
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    cracauer
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Feb 17 11:00:01 PST 1996
>Closed-Date:    Sat Apr 3 13:57:43 MEST 1999
>Last-Modified:  Sat Apr  3 14:01:14 MEST 1999
>Originator:     Mark Murray
>Release:        FreeBSD 2.2-CURRENT i386
>Organization:
GTA
>Environment:

FreeBSD 2.0.5 through -Current (maybe more)

>Description:

Environment variables created "on the fly" are not properly passed
through to compiled code, although subshells seem able to get to them.
This may be a bug in getenv(3).

The following operationg systems do NOT have the problem:

BSDI HP-UX IRIX Linux OSF1 SunOS4 SunOS5 ULTRIX

>How-To-Repeat:

Run the following script:
------------------------------8<-test1----------------------------
#! /bin/sh

echo "-- Shell version"
(echo FOO=/bar/baz ; echo "echo FOO is \$FOO") | /bin/sh -ax
echo "-- Shell version with export"
(echo export FOO=/bar/baz ; echo "echo FOO is \$FOO") | /bin/sh -ax
echo "-- C version"
(echo FOO=/bar/baz ; echo "./env") | /bin/sh -ax
echo "-- C version with export"
(echo export FOO=/bar/baz ; echo "./env") | /bin/sh -ax
------------------------------8<-----------------------------

...where "env" is compiled from this C code:
------------------------------8<-env.c----------------------------
#include <stdlib.h>
#include <stdio.h>

void main(void)
{
	char *foo;

	foo = getenv("FOO");
	if (foo) printf("FOO is %s\n", foo);
	else printf("FOO does not exist!\n");
}
------------------------------8<-----------------------------

... and here is a script of a run:
------------------------------8<-run----------------------------
Script started on Sat Feb 17 20:36:45 1996
bash$ ./test1
-- Shell version
+ FOO=/bar/baz
+ echo FOO is /bar/baz
FOO is /bar/baz
-- Shell version with export
+ export FOO=/bar/baz
+ echo FOO is /bar/baz
FOO is /bar/baz
-- C version
+ FOO=/bar/baz
+ ./env
FOO does not exist!  <----------Lookee here - env did not get the var!
-- C version with export
+ export FOO=/bar/baz
+ ./env
FOO is /bar/baz
bash$ exit
exit

Script done on Sat Feb 17 20:36:53 1996
------------------------------8<-----------------------------


>Fix:
	
Use bash :-). Bash does not have this problem.

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->joerg 
Responsible-Changed-By: joerg 
Responsible-Changed-When: Fri Apr 12 23:36:24 MET DST 1996 
Responsible-Changed-Why:  
I'm goinmg to deal with sh(1) bugs some day. 
State-Changed-From-To: open->analyzed 
State-Changed-By: peter 
State-Changed-When: Sun Sep 1 05:36:13 PDT 1996 
State-Changed-Why:  
Hmm, I believe this (from man sh) would explain it: 
-a    allexport 
Export all variables assigned to.  (UNIMPLEMENTED 
for 4.4alpha) 
Needs to be fixed tho.. 
Responsible-Changed-From-To: joerg->steve 
Responsible-Changed-By: steve 
Responsible-Changed-When: Tue Oct 15 19:08:05 PDT 1996 
Responsible-Changed-Why:  
I am working this one. 
Responsible-Changed-From-To: steve->cracauer 
Responsible-Changed-By: steve 
Responsible-Changed-When: Tue Apr 28 05:56:39 PDT 1998 
Responsible-Changed-Why:  
Martin said he would take this one. 
State-Changed-From-To: analyzed->closed 
State-Changed-By: cracauer 
State-Changed-When: Sat Apr 3 13:57:43 MEST 1999 
State-Changed-Why:  
Fixed in 4.0-current from today. Will be fixed in 3.x in a few 
days. Releases 3.2 and 4.0 should have this change. 

Well, thanks for waiting, anyway :-) I think I spent more time pushing 
around this PR number in my TODO files than the actual fix took. 
>Unformatted:

