Set parent env with csh script

Wolf N. Paul wnp at dcs.UUCP
Sun Jan 8 15:57:26 AEST 1989


In article <174 at v7fs1.UUCP> mvp at v7fs1.UUCP (Mike Van Pelt) writes:
>I would like to write a shell script (csh preferred) that will
>set a few environment variables to various things.  Of course,
>just doing   setenv foo bar  in the script only works for that
>subshell and its children, not for the calling shell.  I've
>gone back and forth through all the likely places in the manuals,
>and haven't found any mention of this.
>
>Is it possible for a subshell to changes the calling shell's 
>environment?  How?

No, it is not possible for a process to change its parent's 
environment.

But what you propose can be accomplished by running the shell
script via "source" (under csh) or "." (under sh or ksh).
Thus, you can put your "setenv" statements into a script, and
then call the script like this:

% source scriptname

or

$ . scriptname

If you don't want to remember this special invocation, create
an alias (under csh, alias scriptname "source scriptname"),
or a shell function (under sh or ksh) to call it.
-- 
Wolf N. Paul * 3387 Sam Rayburn Run * Carrollton TX 75007 * (214) 306-9101
UUCP:     killer!dcs!wnp                 ESL: 62832882
DOMAIN:   dcs!wnp at killer.dallas.tx.us    TLX: 910-380-0585 EES PLANO UD



More information about the Comp.unix.wizards mailing list