home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / unix / shell / 3088 < prev    next >
Encoding:
Internet Message Format  |  1992-07-22  |  2.2 KB

  1. Path: sparky!uunet!autodesk!dansmith
  2. From: dansmith@Autodesk.COM (Daniel Smith)
  3. Newsgroups: comp.unix.shell
  4. Subject: Re: setting variable from script to current environment??
  5. Message-ID: <17149@autodesk.COM>
  6. Date: 22 Jul 92 19:10:40 GMT
  7. References: <1992Jul21.070212.16485@gbrmpa.gov.au>
  8. Organization: Autodesk Inc., Sausalito CA, USA
  9. Lines: 54
  10.  
  11. In <1992Jul21.070212.16485@gbrmpa.gov.au> wayne@gbrmpa.gov.au (Wayne Amisano) writes:
  12. > I am trying to write a script to set an environment variable in
  13. > my tcsh environment.  I could use an alias to do it, but would
  14. > much rather do it from a script.  What i need to do is, run a
  15. > script to change the value of one environment variable, but
  16. > every time i do this, it changes the variable in the spawned
  17. > process, but it then disappears when it dies.
  18.  
  19.     You're halfway there.
  20.  
  21.     Write an alias that *sources* a csh script, and then the
  22. script is free to change any csh or env vars that it wants.
  23.  
  24.     Here's an example for "pushd":
  25.  
  26. bermuda:bermuda/qbuild_dansmith (2) :-) alias p
  27. set cd_attempt=(!*); source ~/bin/p_csh
  28.  
  29. bermuda:bermuda/qbuild_dansmith (2) :-) cat ~/bin/p_csh
  30. #!/bin/echo sorry,try:source
  31. if ($#cd_attempt == 0) set cd_attempt=""
  32. while ($#cd_attempt)
  33.         set o2=$cwd
  34.         set cur_attempt=$cd_attempt[1]
  35.         if ($cur_attempt !~ "") then
  36.                 if (! -d $cur_attempt) then
  37.                         set cur_attempt=$cur_attempt:h
  38.                 endif
  39.         endif
  40.         pushd $cur_attempt > /dev/null
  41.         echo $cwd
  42.         set old=$o2
  43.         dir_number
  44.         shift cd_attempt
  45. end
  46. prompt_set
  47.  
  48. and then the aliases for dir_number and prompt_set:
  49.  
  50. bermuda:bermuda/qbuild_dansmith (2) :-) alias dir_number
  51. set fillstr; set dnum=`dirs`; shift dnum; \
  52.      if ($#dnum >= 1) set fillstr=" ($#dnum)"
  53.  
  54. and:
  55.  
  56. bermuda:bermuda/qbuild_dansmith (2) :-) alias prompt_set
  57. set prompt_head=$cwd:h;set prompt="$HOST"":$prompt_head:t/$cwd:t$fillstr $end "
  58.  
  59.                 Daniel
  60. -- 
  61.             dansmith@autodesk.com            dansmith@well.sf.ca.us
  62.         Daniel Smith, Autodesk, Sausalito, California, (415) 332-2344 x 2580
  63.               Disclaimer: written by a highly caffeinated mammal
  64.  $|=1;for("..."," hacker"," perl"," a","just"){print $l=$_.$l,"\015";sleep 1;}
  65.