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

  1. Newsgroups: comp.unix.shell
  2. Path: sparky!uunet!usc!sol.ctr.columbia.edu!The-Star.honeywell.com!umn.edu!s6.math.umn.edu!rantapaa
  3. From: rantapaa@s6.math.umn.edu (Erik E. Rantapaa)
  4. Subject: Re: Array and looping in Bourne Shell
  5. Message-ID: <rantapaa.714542978@s6.math.umn.edu>
  6. Sender: news@news2.cis.umn.edu (Usenet News Administration)
  7. Nntp-Posting-Host: s6.math.umn.edu
  8. Organization: University of Minnesota
  9. References: <peter.714447819@merlin>
  10. Date: Sun, 23 Aug 1992 04:09:38 GMT
  11. Lines: 36
  12.  
  13. peter@merlin.acadiau.ca (Peter Steele) writes:
  14.  
  15. >I need to write a script that takes a list and generates
  16. >various permutations of that list, e.g., if the list is
  17. >"a b c", I want to generate the following data sets:
  18. ...
  19.  
  20. I guess that you want all strings "p1 p2" where p1 and p2 are
  21. prefixes of 'a,b,...' and p1 is a prefix of p2.
  22.  
  23. In that case, try this.  (Invoke as 'script a b c', for example.)
  24.  
  25. #!/bin/sh
  26. (
  27.     mkdir /tmp/abc$$
  28.     cd /tmp/abc$$
  29.     f=
  30.     for x
  31.     do
  32.         cat < /dev/null > "$f$x"
  33.         f="$f$x,"
  34.     done
  35.     for x in * ;
  36.     do
  37.         for y in `echo $x*` ;
  38.         do
  39.             echo $x $y
  40.         done
  41.     done
  42.     rm -rf /tmp/abc$$
  43. ) | sort # just in case globbing doesn't return files in alphabetical order
  44. --
  45.         Erik Rantapaa                   rantapaa@math.umn.edu
  46.  
  47.  Imagination is the one weapon in the war against reality.
  48.          -- Jules de Gaultier
  49.