home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / unix / shell / 5503 < prev    next >
Encoding:
Text File  |  1993-01-27  |  2.0 KB  |  51 lines

  1. Newsgroups: comp.unix.shell
  2. Path: sparky!uunet!munnari.oz.au!sgiblab!spool.mu.edu!yale.edu!ira.uka.de!math.fu-berlin.de!mailgzrz.TU-Berlin.DE!news.netmbx.de!Germany.EU.net!mcsun!sunic!palantir.p.tvt.se!infolog!mich
  3. From: mich@lin.infolog.se (Thomas Michanek)
  4. Subject: Re: Setting enviroment variables in a shell script
  5. Message-ID: <1993Jan26.091447.2303@infolog.se>
  6. Keywords: environment variables shell script
  7. Sender: news@infolog.se
  8. Organization: Infologics, Linkoping, Sweden
  9. References: <35774@sales.GBA.NYU.EDU> <1993Jan25.003213.3784@lri.fr> <18469@autodesk.COM>
  10. Date: Tue, 26 Jan 1993 09:14:47 GMT
  11. Lines: 38
  12.  
  13. In article <18469@autodesk.COM> dls@Autodesk.COM (Daniel Louis Smith) writes:
  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.  
  26.  
  27. Good idea, except that you don't have to use a separate variable to
  28. store the command line arguments. In general, you can make an alias like:
  29.  
  30.   alias <name> "source <filename> '\!*'"
  31.  
  32. In the source'd file <filename> you put:
  33.  
  34.   set argv = `echo \!*`
  35.  
  36. as the first command. You can now use $1, $2, etc. as in an ordinary script:
  37.  
  38.   if ($#argv > 0) then
  39.     setenv MYVAR $1  # or whatever
  40.     ...
  41.   endif
  42.  
  43. Works like a dream!
  44.  
  45. .- - - - - - - - - - - -.  _ _  _ ___ _  _   _   _  _  _  _   .- - - - - - - -.
  46. |    Thomas Michanek    |  | |\ | |_ / \ |  / \ / _ | / `|_`  | Dial +46 13   |
  47. |  Infologics Linkoping |  | | \| |  \_/ |_,\_/ \_| | \_,._|  | 210060  Phone |
  48. | email:Thomas.Michanek |          _                          | 210068  Direct|
  49. |       @lin.infolog.se |  L I N K O P I N G  -  S W E D E N  | 210155  Fax   |
  50. `- - - - - - - - - - - -'                                     `- - - - - - - -'
  51.