[vox-tech] Bash script to setup environment variables

Mark K. Kim vox-tech@lists.lugod.org
Thu, 27 Dec 2001 23:33:07 -0800 (PST)


Hmm... can you think of any other ways?

I'm trying to run a script, not a C program.  Also, I don't know about
Unix but under DOS putenv() doesn't affect the parent program that called
the C program (it affects only itself and the children.)

-Mark

On Thu, 27 Dec 2001, Henry House wrote:

> On Thu, Dec 27, 2001 at 11:12:35PM -0800, Mark K. Kim wrote:
> > Keywords: bash, script, environment variables
> >
> > I'm doing some cross-compilation work so I need to flip environment
> > variables on/off in a heartbeat.  I tried to write a script, but script=
s
> > run on sub-processes so the changes do not take effect on the parent
> > process.  Is there a way, without having to type `source script` or `.
> > script`, to make environment variables changes take place on the runnin=
g
> > process?
>
> Would putenv(3) work? To quote the manual:
>
> NAME
> =09=09 putenv - change or add an environment variable
>
> SYNOPSIS
> =09=09 #include <stdlib.h>
>
> =09=09 int putenv(char *string);
>
> DESCRIPTION
> =09=09 The  putenv()  function  adds  or  changes the value of environmen=
t variables.  The
> =09=09 argument string is of the form name=3Dvalue.  If name does not alr=
eady exist  in  the
> =09=09 environment, then string is added to the environment.  If name doe=
s exist, then the
> =09=09 value of name in the environment is changed to value.  The  string=
  pointed  to  by
> =09=09 string becomes part of the environment, so altering the string cha=
nges the environ=AD
> =09=09 ment.
>
> --
> Henry House
> The attached file is a digital signature. See <http://romana.hajhouse.org=
/pgp>
> for information.  My OpenPGP key: <http://romana.hajhouse.org/hajhouse.as=
c>.
>

--
Mark K. Kim
http://www.cbreak.org/mark/
PGP key available upon request.