Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 17 Feb 1996 20:56:16 +0200 (SAT)
From:      Mark Murray <mark@grondar.za>
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   bin/1030: /bin/sh does not pass environment variables on properly
Message-ID:  <199602171856.UAA13002@grumble.grondar.za>
Resent-Message-ID: <199602171900.LAA23168@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         1030
>Category:       bin
>Synopsis:       /bin/sh does not pass environment variables on properly
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sat Feb 17 11:00:01 PST 1996
>Last-Modified:
>Originator:     Mark Murray
>Organization:
GTA
>Release:        FreeBSD 2.2-CURRENT i386
>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.

>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199602171856.UAA13002>