Set parent env with csh script

Chris Torek chris at mimsy.UUCP
Sun Jan 8 15:55:14 AEST 1989


In article <174 at v7fs1.UUCP> mvp at v7fs1.UUCP (Mike Van Pelt) writes:
>Is it possible for a subshell to changes the calling shell's environment?

Yes.

>How?

By getting the cooperation of the calling shell.  For instance:

	#! /bin/sh
	# edit environment variable
	case $# in 1);; *) echo "usage: edit-env varname" 1>&2; exit 1;; esac
	TF=${TMPDIR-/tmp}/edenv$$
	rm -f $TF
	trap 'rm -f $TF; exit 1' 1 2 3 15
	trap 'rm -f $TF; exit' 0
	eval echo "$1" > $TF
	if ${EDITOR-vi} $TF </dev/tty >/dev/tty 2>&1; then
		echo "setenv $1 `cat $TF`"	# csh-specific
	fi

Then:

	% alias edit-env 'eval `~/bin/edit-env`'
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris at mimsy.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.unix.wizards mailing list