csh setenv problem

Dr. Scump aland at infmx.UUCP
Thu Aug 17 11:54:13 AEST 1989


In article <SAAF.89Aug16153940 at joker.optics.rochester.edu> saaf at 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



More information about the Comp.unix.questions mailing list