Path: utzoo!utgpu!attcan!uunet!lll-winken!lll-tis!ames!mailrus!cornell!uw-beaver!mit-eddie!bbn!spdcc!dyer From: dyer@spdcc.COM (Steve Dyer) Newsgroups: comp.unix.xenix Subject: Re: Changing the environment in sh Keywords: sh export shell Message-ID: <1778@spdcc.COM> Date: 2 Sep 88 17:37:15 GMT References: <59@csnz.nz> Reply-To: dyer@spdcc.COM (Steve Dyer) Organization: S.P. Dyer Computer Consulting, Cambridge MA Lines: 23 There is no way to change a shell environment variable directly from a child process, because the environment is an attribute of each process, and is not a global resource. A child process inherits the environment of its parent (at least if it's invoked from a shell or via the system call execve), but it then owns a separate copy of the environment in its own address space--you can change things all day and it won't make any different to the parent process and any siblings which might be around. The only way to have a subprocess change the parent's environment is to set up some form of convention to communicate this. For example, if you had a program which wrote out environment variable assignments (in some shell's syntax) to the standard output, you could invoke the command from the shell in the form: eval `command` The parent shell would be reading the shell variable reassignments and changing them in its own context. If your shell supported it (csh, ksh), you could make this more convenient by using aliases. -- Steve Dyer dyer@harvard.harvard.edu dyer@spdcc.COM aka {harvard,husc6,linus,ima,bbn,m2c,mipseast}!spdcc!dyer