home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / unix / shell / 5495 < prev    next >
Encoding:
Internet Message Format  |  1993-01-25  |  1.9 KB

  1. Path: sparky!uunet!nntp1.radiomail.net!fernwood!autodesk!dls
  2. From: dls@Autodesk.COM (Daniel Louis Smith)
  3. Newsgroups: comp.unix.shell
  4. Subject: Re: Setting enviroment variables in a shell script
  5. Keywords: environment variables shell script
  6. Message-ID: <18469@autodesk.COM>
  7. Date: 25 Jan 93 19:36:24 GMT
  8. References: <35774@sales.GBA.NYU.EDU> <1993Jan25.003213.3784@lri.fr>
  9. Organization: Autodesk Inc., Sausalito CA, USA
  10. Lines: 44
  11.  
  12. In <1993Jan25.003213.3784@lri.fr> wacren@lri.fr (Laurent WACRENIER) writes:
  13.  
  14.  
  15. > In article <35774@sales.GBA.NYU.EDU>, elouie@sales.GBA.NYU.EDU (Euge) writes:
  16. > |> How do you set an environment variable in a C-Shell script?  I tried
  17. > |> setenv enviroment_variable value, but as soon as the script finishes, 
  18. > |> the value of the varialbe is reset to its original value.  My guess is 
  19.  
  20.     My favorite way is to source bits of csh...  example:
  21.  
  22. bermuda:dls/bin (1) :-) alias newdir
  23. set newdir_attempt=(!*); source $HOME/bin/newdir_csh
  24.  
  25. bermuda:dls/bin (1) :-) cat newdir_csh
  26. #!/bin/echo sorry,try:source
  27. if ($#newdir_attempt == 0) then
  28.         echo 'usage: newdir dir_to_make [files to move to dir_to_make]'
  29.         goto nd_end
  30. endif
  31.  
  32. mkdir $newdir_attempt[1] || goto nd_end
  33. set cd_attempt=$newdir_attempt[1]
  34. if ($#newdir_attempt > 1) then
  35.         shift newdir_attempt
  36.         mv -f $newdir_attempt $cd_attempt
  37.         unset newdir_attempt
  38. endif
  39. pl $cd_attempt   # this is a pushd and ls alias
  40.  
  41. nd_end:
  42. bermuda:dls/bin (1) :-)
  43.  
  44.     Now note that I haven't mentioned environment variables yet.  It
  45. doesn't matter - the idea is to set up an alias which sets a variable
  46. which gets passed to a csh script which is *sourced*.  You can change
  47. whatever you need to (csh or env vars) this way.
  48.  
  49.                     Daniel
  50.  
  51.  
  52. -- 
  53.          dls@autodesk.com              dansmith@well.sf.ca.us
  54.      Daniel L Smith, Autodesk, Sausalito, California, (415) 332-2344 x 2580
  55.            formerly dansmith@autodesk.com, changed my login recently
  56.