home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / unix / shell / 3701 < prev    next >
Encoding:
Text File  |  1992-08-30  |  1.7 KB  |  53 lines

  1. Newsgroups: comp.unix.shell
  2. Path: sparky!uunet!haven.umd.edu!darwin.sura.net!wupost!sdd.hp.com!usc!sol.ctr.columbia.edu!destroyer!ubc-cs!dhami
  3. From: dhami@cs.ubc.ca (Mandeep S Dhami)
  4. Subject: > alias problems
  5. Message-ID: <1992Aug31.013437.16476@cs.ubc.ca>
  6. Summary: problem solved.
  7. Keywords: problem solved.
  8. Sender: usenet@cs.ubc.ca (Usenet News)
  9. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  10. Date: Mon, 31 Aug 92 01:34:37 GMT
  11. Lines: 40
  12.  
  13.  
  14. Mickey <mickey@sfera.kharkov.ua>:
  15. >
  16. >  there is a little problem to write alias in such way:
  17. >  alias md "sh -c 'for f in \!*;do mkdir $f ; cd $f;done'"
  18. >  it have to do:
  19. >    make directory, than cd to it;
  20. >  call:
  21. >    cd ~
  22. >    md 1 2 3 4 5 6
  23. >  result:
  24. >    cwd = ~/1/2/3/4/5/6
  25. >
  26. >  In such way implementation there are a couple of errors reported,
  27. >  including "f": variable not found, and so on...
  28. >
  29.  
  30. As already pointed out sh -c can NEVER work as, under UNIX, the
  31. child can not touch the parents env. So you want to source OR in
  32. *sh use function and in csh an alias which does NOT cd in a
  33. subshell.
  34.  
  35. So one possible solution (csh for you) is:
  36. alias xx 'set x=`echo \!*| tr " " "/"`; mkdir -p $x; cd $x;unset x;'
  37. Note:
  38.   1. cd in parent shell's context and
  39.   2. -p in mkdir.
  40.  
  41. Or same as a better function in sane shells (*sh).
  42.  
  43. BTW, the error you had above is due to the brain dead parsing
  44. in csh (refer to Tom Christiansen's wonderful critique of csh).
  45. Maybe Tom should make it a regular posting!
  46.  
  47. Mandeep.
  48. --
  49. __________________________________________________________________
  50. "I'm very brave generally," he went on in a low voice:
  51. "only to-day I happen to have a headache."
  52.                                       -- Lewis Carroll
  53.