Re: export does not work on makefiles

From: John Gordon (gordon_at_panix.com)
Date: 12/06/04


Date: Mon, 6 Dec 2004 20:20:31 +0000 (UTC)

In <cp25dr$323$1@news2.rz.uni-karlsruhe.de> Uwe Mayer <merkosh@hadiko.de> writes:

> If I have a Makefile like:

> test:
> export test=5

> why does this not cause the environment variable test to be visible after
> execution of make?

In general, whenever you run a command (such as make), that command runs
as a separate process with its own copy of the parent process' environment.

If that command makes any changes to the environment (such as exporting
variables), those changes apply only to its copy of the environment, NOT
to the environment of the parent shell which spawned that process.

And that's exactly what happened here. You ran make, which starts up a
new child process. That child process modified its environment and then
immediately exited.

It's a Very Good Thing that child processes cannot modify the environment
of parent processes. Trust me.

-- 
John Gordon        "Between BST melee, their spells, their warders' melee,
gordon@panix.com    and their warders' procs, they put out enough damage
                    to make monks cry." -- Dark Tyger


Relevant Pages

  • Re: Shared memory and error 997
    ... CreateProcess(...including szName in the command line ... >> CreateFileMappingin the parent process. ... >> command line parameter to the child process. ... >> shared memory using OpenFileMappingit fails and GetLastError() ...
    (microsoft.public.vc.language)
  • Re: Persistent connections
    ... do you get a persistent PHP ... the at command (from an SSH ... HUP to all child process. ... expired - the method described above just changes the parent process ...
    (comp.lang.php)
  • Re: Script export problem in FC3
    ... > I need to modify the PATH environment using a script. ... > If I run the export command in command line I have no problem, ... The child process has the new environment, ...
    (Fedora)
  • kill(child_pid, SIGSTOP);
    ... and accept user to type in command use execvpto execute user command ... if process receives SIGSTOP while child process running on ... parent process to continue to accept new command? ...
    (comp.os.linux.development.system)
  • Re: unix shell script ignores exit when in function that is piped to tee
    ... > process is fed into the stdin of the parent process that's running the right ... > hand side of the command. ... If there is a child process it should have a different process-id, ... But I tried printing out the pid to a file from within the ...
    (comp.unix.shell)