Script to set parent environment

arf mvp at v7fs1.UUCP
Wed Jan 18 09:28:27 AEST 1989


Some time ago I asked about how a csh script could change
global environment variables.  Thanks to everyone who responded.

Here's a summary:

You can't do it, and this question should be added to the 
"List of Most Frequently Asked Questions".

At least, there's no official way, because to do that requires a
child to change its parent's environment, and that's a no-no.  A
couple of messages implied that it might be possible, if one were
to play some "Real Programmer" type games.  Many replies also
said that if I wanted to call a script to set some environment
variables, I should either "source" the script ( . in sh) or
create an alias.  (I had ruled out sourcing the script because
you can't pass arguments to a sourced script.)

chris at mimsy.UUCP (Chris Torek) suggested a script which
generates and then prints the desired setenv command on standard
output, and an alias

>	% alias edit-env 'eval `~/bin/edit-env`'

to make the current shell do the actual setenv.  This works
fine, but doesn't work for the specific problem I was trying to
solve -- a script which saves its argument list, and if called
with no arguments, uses the old argument list.  (Perhaps I
should have specified what I was trying to do more exactly.)

The way I finally kludged it was more along the lines of

if $#argv > 0 then
	echo $* >~/.last-parms
endif
program-call `cat ~/.last-parms`

-- 
Mike Van Pelt                                 "Hey, hey, ho ho,
Video 7                                       Western culture's got to go."
...ames!vsi1!v7fs1!mvp                        Stanford students and faculty.



More information about the Comp.unix.wizards mailing list