home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.shell
- Path: sparky!uunet!usc!sol.ctr.columbia.edu!The-Star.honeywell.com!umn.edu!s6.math.umn.edu!rantapaa
- From: rantapaa@s6.math.umn.edu (Erik E. Rantapaa)
- Subject: Re: Array and looping in Bourne Shell
- Message-ID: <rantapaa.714542978@s6.math.umn.edu>
- Sender: news@news2.cis.umn.edu (Usenet News Administration)
- Nntp-Posting-Host: s6.math.umn.edu
- Organization: University of Minnesota
- References: <peter.714447819@merlin>
- Date: Sun, 23 Aug 1992 04:09:38 GMT
- Lines: 36
-
- peter@merlin.acadiau.ca (Peter Steele) writes:
-
- >I need to write a script that takes a list and generates
- >various permutations of that list, e.g., if the list is
- >"a b c", I want to generate the following data sets:
- ...
-
- I guess that you want all strings "p1 p2" where p1 and p2 are
- prefixes of 'a,b,...' and p1 is a prefix of p2.
-
- In that case, try this. (Invoke as 'script a b c', for example.)
-
- #!/bin/sh
- (
- mkdir /tmp/abc$$
- cd /tmp/abc$$
- f=
- for x
- do
- cat < /dev/null > "$f$x"
- f="$f$x,"
- done
- for x in * ;
- do
- for y in `echo $x*` ;
- do
- echo $x $y
- done
- done
- rm -rf /tmp/abc$$
- ) | sort # just in case globbing doesn't return files in alphabetical order
- --
- Erik Rantapaa rantapaa@math.umn.edu
-
- Imagination is the one weapon in the war against reality.
- -- Jules de Gaultier
-