Path: utzoo!utgpu!watmath!att!bellcore!texbell!wuarchive!wugate!uunet!tut.cis.ohio-state.edu!ucbvax!agate!apple!oliveb!pyramid!infmx!aland From: aland@infmx.UUCP (Dr. Scump) Newsgroups: comp.unix.questions Subject: Re: csh setenv problem Summary: use source(1) to process commands in current csh Message-ID: <2135@infmx.UUCP> Date: 17 Aug 89 01:54:13 GMT References:Reply-To: aland@infmx.UUCP (alan denney) Organization: INFORMIX Professional Services ("Peace thru Normalization") Lines: 44 In article saaf@joker.optics.rochester.edu (Lenny Saaf) writes: >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: Let's see if I word this one a little more carefully so I don't get flamed like last time: This won't work because you are exporting to the shell spawned to run your shell script -- when the script ends, that shell is gone. You can't run a shell script and have it effect the calling environment. HOWEVER, you can process the commands in your *current* shell to get the effect you want. You can process commands from a file using the "source" command (for csh) or the "." command (sh). ># csh script ># filename is testscript >setenv FOO 'bar' >echo $FOO ># end >The result: >[1]% chmod +x testscript >[2]% testscript here, you should be saying "source testscript". execute permission is not necessary. >bar >[3]% echo $FOO >FOO: Undefined variable. >What am I missing? >* Len Saaf, The Institute of Optics, University of Rochester, Rochester, NY * -- Alan S. Denney @ Informix Software, Inc. {pyramid|uunet}!infmx!aland "I want to live! -------------------------------------------- as an honest man, Disclaimer: These opinions are mine alone. to get all I deserve If I am caught or killed, the secretary and to give all I can." will disavow any knowledge of my actions. - S. Vega