home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / unix / shell / 3485 < prev    next >
Encoding:
Text File  |  1992-08-13  |  1.9 KB  |  55 lines

  1. Newsgroups: comp.unix.shell
  2. Path: sparky!uunet!mcsun!sunic!aun.uninett.no!ugle.unit.no!lise.unit.no!arnej
  3. From: arnej@Lise.Unit.NO (Arne Henrik Juul)
  4. Subject: Re: Escaping brackets in csh - SUMMARY
  5. Message-ID: <1992Aug14.033445.13259@ugle.unit.no>
  6. Sender: news@ugle.unit.no (NetNews Administrator)
  7. Reply-To: arnej@lise.unit.no
  8. Organization: Norwegian Institute of Technology
  9. References: <1992Aug12.234645.2589@newshost.lanl.gov> <glaze.093@glaze>
  10. Date: Fri, 14 Aug 92 03:34:45 GMT
  11. Lines: 42
  12.  
  13. In article <glaze.093@glaze>, glaze@cs.mu.oz.au (Glaze) writes:
  14.  > One thing you may need to do is change the ``mkdir'' to ``mkdir -p'' above.
  15.  > The -p option requesting that mkdir create any missing parent directories.
  16.  > However, older mkdir's don't support it, so here's a small script I
  17.  > whipped up for you:
  18.  
  19. Wrong - it was already in the script. Read it carefully:
  20.  
  21. #!/bin/sh
  22. /bin/ls \[* | while read filename; do
  23.     dir=`echo $filename | sed 's/^\[\(.*\)\].*/\1/' | tr . /`
  24.     dirs=`echo $filename | sed 's/^\[\(.*\)\].*/\1/' | tr . ' '`
  25.     file=`echo $filename | sed 's/^\[.*\]//'`
  26.     set $dirs
  27.     ( for x do mkdir $x 2>/dev/null; cd $x; done )
  28.     echo making $dir/$file
  29.     cp $filename $dir/$file
  30. done
  31.  
  32.  
  33. The 'for' loop is in there just to make the subdirectories in the
  34. needed order, like this:
  35.  
  36. filename is '[asdf.zxcv]qwer'.
  37. after the "dirs=" line, the dirs variable is "asdf zxcv".
  38. after the set line, $1 is asdf, $2 is zxcv.
  39. in the for loop, x get set to $1 $2 ..., that is asdf first, then zxcv.
  40. asdf is mkdir'd, and we cd into asdf.
  41. zxcv is mkdir'd, and we cd into zxcv.
  42.  
  43. This is why the ( ) is there - we don't want the main loop to cd into
  44. asdf/zxcv, so we just loose that subprocess.
  45.  
  46.  
  47. Did you test it? No. Did I test it? Yes.
  48.  
  49. Moral: Never ever post anything without testing first (unless you're a
  50. wizard, which I am not, and which you apparently are not :-).
  51.  
  52.  
  53. --
  54. Arne H. Juul  --  arnej@lise.unit.no  --  University of Trondheim, Norway
  55.