home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!uknet!siesoft!wstuart!stuart
- From: stuart@wstuart (Stuart Hood)
- Newsgroups: comp.unix.shell
- Subject: Re: alias problems
- Message-ID: <1992Sep2.184806.2497@siesoft.co.uk>
- Date: 2 Sep 92 18:48:06 GMT
- References: <1992Aug29.140835.15176@sfera.kharkov.ua>
- Sender: news@siesoft.co.uk (Usenet News)
- Reply-To: stuart@siesoft.co.uk
- Organization: Siemens Nixdorf Information Systems Ltd.
- Lines: 54
- X-Newsreader: Tin 1.1 PL4
-
- mickey@sfera.kharkov.ua (Mickey Serg Antonoff) writes:
- :
- : 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
- :
-
- This doesn't work because "sh -c" starts up a new process.
- New processes inherit their parent's environment (including
- "cwd") but cannot (sensibly) alter their parent's environment.
-
- A common "trick" to get round this problem is for the child
- process to "echo" the result of its task and for the parent
- to use that output in some way. Something like:
-
- cd `sh -c 'for f in 1 2 3 4 5 6; \
- do mkdir $f; cd $f; echo -n $f/; done; echo'`
-
- would change the "cwd" of the current process. So an alias
- along the lines of:
-
- alias md cd \`sh -c \'for f in \!\* \; \
- do mkdir \$f \; cd \$f \; echo -n \$f/ \; done \; echo\'\`
-
- should do what is required.
-
- Note: the use of '\' is needed to avoid the problem of:
- "f": variable not found
-
- This looks too messy to my mind so I would prefer to use
- "source" and a file. Given the file:
-
- # $HOME/.md
- foreach d ( $list )
- mkdir $d
- cd $d
- end
-
- then we can implement the simple alias:
-
- alias md 'set list = "\!*" ; source ~/data/md'
-
- Stuart.
- -
- --
- S I E M E N S Stuart Hood === Siemens Nixdorf House, Bracknell, Berks, UK
- ------------- Phone: + 44-344-850892 Email: stuart@siesoft.co.uk
- N I X D O R F - Never let ignorance stand in the way of a good argument -
-