From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21054 invoked from network); 23 Jul 2005 19:39:58 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 23 Jul 2005 19:39:58 -0000 Received: (qmail 39310 invoked from network); 23 Jul 2005 19:39:50 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 23 Jul 2005 19:39:50 -0000 Received: (qmail 4547 invoked by alias); 23 Jul 2005 19:39:44 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 9133 Received: (qmail 4537 invoked from network); 23 Jul 2005 19:39:44 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 23 Jul 2005 19:39:44 -0000 Received: (qmail 38333 invoked from network); 23 Jul 2005 19:39:43 -0000 Received: from ns9.hostinglmi.net (213.194.149.146) by a.mx.sunsite.dk with SMTP; 23 Jul 2005 19:39:38 -0000 Received: from 212.red-80-35-44.pooles.rima-tde.net ([80.35.44.212] helo=localhost) by ns9.hostinglmi.net with esmtpa (Exim 4.51) id 1DwPqX-0001FM-0u for zsh-users@sunsite.dk; Sat, 23 Jul 2005 21:39:41 +0200 Date: Sat, 23 Jul 2005 21:42:40 +0200 From: DervishD To: Zsh Users Subject: Sorting file names randomly Message-ID: <20050723194240.GA32416@DervishD> Mail-Followup-To: Zsh Users Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit User-Agent: Mutt/1.4.2.1i Organization: DervishD X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - ns9.hostinglmi.net X-AntiAbuse: Original Domain - sunsite.dk X-AntiAbuse: Originator/Caller UID/GID - [0 0] / [47 12] X-AntiAbuse: Sender Address Domain - dervishd.net X-Source: X-Source-Args: X-Source-Dir: X-Spam-Checker-Version: SpamAssassin 3.0.4 (2005-06-05) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00 autolearn=ham version=3.0.4 Hi all :) A time ago (zsh-workers/19128) Bart explained me how to sort randomly a group of files. Namely, the solution is this: array=(*(e:'reply=%0(l..$RANDOM)$REPLY:)) array=(${(%)array) Just as a side note, this works because that %0... construct, which is a prompt escape sequence, namely a conditional that says "if more than 0 characters have been printed, print nothing, else print the $RANDOM expansion). Obviously this is always false so the random number is never printed but it is used for sorting. Well, the problem is that the above doesn't work if you have to use more than one pattern, because the '(e' construct will affect only the last element. Since I don't know how many elements will be present, I cannot use an '(e' construct on each element. Moreover it would be very messy. What I want to do is to generate (in an array) a list of files sorted randomly, given some globbing patterns. Since the list can be quite large, I think that doing the glob on the command line is not a good idea, so I would call the function like: shuffle dir1/* dir2/* ... The globbing will be internal, so 'shuffle' is really an alias to "noglob 'shuffle'". I've tried to use '$~' in the solution above (the '%0...' one), but it doesn't work because although files in dir1 and files in dir2 are sorted randomly, dir1 files appear always before dir2 files. It seems that the random number doesn't affect the sorting of pathnames :? Any simple way of using the above solution for this new problem or should I try a new solution? Any simple way of doing the random sort on a group of patterns? Thanks a lot in advance :) Raúl Núñez de Arenas Coronado -- Linux Registered User 88736 | http://www.dervishd.net http://www.pleyades.net & http://www.gotesdelluna.net It's my PC and I'll cry if I want to...