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