home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.shell
- Path: sparky!uunet!mcsun!sunic!aun.uninett.no!ugle.unit.no!lise.unit.no!arnej
- From: arnej@Lise.Unit.NO (Arne Henrik Juul)
- Subject: Re: Escaping brackets in csh - SUMMARY
- Message-ID: <1992Aug14.033445.13259@ugle.unit.no>
- Sender: news@ugle.unit.no (NetNews Administrator)
- Reply-To: arnej@lise.unit.no
- Organization: Norwegian Institute of Technology
- References: <1992Aug12.234645.2589@newshost.lanl.gov> <glaze.093@glaze>
- Date: Fri, 14 Aug 92 03:34:45 GMT
- Lines: 42
-
- In article <glaze.093@glaze>, glaze@cs.mu.oz.au (Glaze) writes:
- > One thing you may need to do is change the ``mkdir'' to ``mkdir -p'' above.
- > The -p option requesting that mkdir create any missing parent directories.
- > However, older mkdir's don't support it, so here's a small script I
- > whipped up for you:
-
- Wrong - it was already in the script. Read it carefully:
-
- #!/bin/sh
- /bin/ls \[* | while read filename; do
- dir=`echo $filename | sed 's/^\[\(.*\)\].*/\1/' | tr . /`
- dirs=`echo $filename | sed 's/^\[\(.*\)\].*/\1/' | tr . ' '`
- file=`echo $filename | sed 's/^\[.*\]//'`
- set $dirs
- ( for x do mkdir $x 2>/dev/null; cd $x; done )
- echo making $dir/$file
- cp $filename $dir/$file
- done
-
-
- The 'for' loop is in there just to make the subdirectories in the
- needed order, like this:
-
- filename is '[asdf.zxcv]qwer'.
- after the "dirs=" line, the dirs variable is "asdf zxcv".
- after the set line, $1 is asdf, $2 is zxcv.
- in the for loop, x get set to $1 $2 ..., that is asdf first, then zxcv.
- asdf is mkdir'd, and we cd into asdf.
- zxcv is mkdir'd, and we cd into zxcv.
-
- This is why the ( ) is there - we don't want the main loop to cd into
- asdf/zxcv, so we just loose that subprocess.
-
-
- Did you test it? No. Did I test it? Yes.
-
- Moral: Never ever post anything without testing first (unless you're a
- wizard, which I am not, and which you apparently are not :-).
-
-
- --
- Arne H. Juul -- arnej@lise.unit.no -- University of Trondheim, Norway
-