home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / unix / shell / 3130 < prev    next >
Encoding:
Internet Message Format  |  1992-07-25  |  1.9 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: <17223@autodesk.COM>
  6. Date: 24 Jul 92 22:37:48 GMT
  7. References: <1992Jul21.070212.16485@gbrmpa.gov.au> <1992Jul22.014834.1384@jpradley.jpr.com> <1992Jul23.191928.4948@walter.bellcore.com>
  8. Organization: Autodesk Inc., Sausalito CA, USA
  9. Lines: 43
  10.  
  11. In <1992Jul23.191928.4948@walter.bellcore.com> snk@fork.bae.bellcore.com (Samuel N Kamens) writes:
  12. > One thing to be careful of when you source shells -- if those shells
  13. > have an "exit" in them, that will cause the *PARENT* process to exit.
  14.  
  15. > I can't count how many times I have sourced a file that did an exit
  16. > and watched my xterm disappear..... :-(
  17.  
  18.  
  19.     Right, a good thing to do is have a label to go to at the end:
  20.  
  21. #!/bin/echo sorry,try:source
  22. if ($#newdir_attempt == 0) then
  23.         echo 'usage: newdir dir_to_make [files to move to dir_to_make]'
  24.         goto nd_end
  25. endif
  26.  
  27. mkdir $newdir_attempt[1] || goto nd_end
  28. set cd_attempt=$newdir_attempt[1]
  29. if ($#newdir_attempt > 1) then
  30.         shift newdir_attempt
  31.         mv -f $newdir_attempt $cd_attempt
  32.         unset newdir_attempt
  33. endif
  34. pl $cd_attempt
  35.  
  36. nd_end:
  37.  
  38.  
  39.     this example makes a directory, moves any files you specify
  40. into it, and pushd's the new directory (the pl alias).  Called as:
  41.  
  42. alias newdir 'set newdir_attempt=(\!*); source ~/bin/newdir_csh'
  43.  
  44.     It's probably good practice to call the end labels something
  45. different in each script, or you may confuse the shell as to which
  46. "end:" you mean.
  47.  
  48.                 Daniel
  49. -- 
  50.             dansmith@autodesk.com            dansmith@well.sf.ca.us
  51.         Daniel Smith, Autodesk, Sausalito, California, (415) 332-2344 x 2580
  52.               Disclaimer: written by a highly caffeinated mammal
  53.  $|=1;for("..."," hacker"," perl"," a","just"){print $l=$_.$l,"\015";sleep 1;}
  54.