Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.csd.uwm.edu!cs.utexas.edu!uunet!mcvax!ukc!axion!iwarner From: iwarner@zaphod.axion.bt.co.uk (Ivan Warner,G44 SSTF,6632,) Newsgroups: comp.unix.questions Subject: Re: csh setenv problem Message-ID: <2312@zaphod.axion.bt.co.uk> Date: 18 Aug 89 14:04:13 GMT References: Sender: news@axion.bt.co.uk Reply-To: iwarner@zaphod.axion.bt.co.uk Lines: 42 From article , by saaf@joker.optics.rochester.edu (Lenny Saaf): > I want to execute a csh script and set some variables for use in the > parent shell. As I understand it, the script in the file is executed > in a subshell, so I think I have to "export" any csh variables I set > in the shell script. That is, use setenv as opposed to set. Well, I > can't seem to get it to work. The shell script file looks like this: > > # csh script > # filename is testscript > setenv FOO 'bar' > echo $FOO > # end > > The result: > > [1]% chmod +x testscript > [2]% testscript > bar > [3]% echo $FOO > FOO: Undefined variable. Yes, the script is run in a sub-shell. But, anything set up using setenv is not passed back to the parent shell either. As soon as the child shell exits, all environment variables are thrown away. The environment variables are, however, passed down from parent to child (set variables are not). The Bourne Shell (sh) has an export command, which exports a variable to the parent shell. Csh does not have this. You have to 'source' the script file, i.e. source filename instead of just 'filename'. This runs the script in the current shell (without spawning a sub-shell). Any setenvs/set/alias commands will be in effect when this is done. You cannot have parameters to the script file when using 'source' though (I think). Ivan Warner