[clug] Shell glob for a range of numbers?

James Ring sjr at jdns.org
Fri Jan 9 03:55:07 GMT 2004


How about another guess...

You want to copy files in the range argus.log.[5..21].gz, but what you
really get
is files in the range argus.log.[1..16].gz.

Maybe... give me free pizza! ;-)

James

----- Original Message -----
From: "Michael Still" <mikal at stillhq.com>
To: "Andrew Bishop" <andrew at bishop.dropbear.id.au>
Cc: <linux at lists.samba.org>
Sent: Friday, January 09, 2004 1:34 PM
Subject: RE: [clug] Shell glob for a range of numbers?


> On Fri, 9 Jan 2004, Andrew Bishop wrote:
>
> > On Fri, 9 Jan 2004, McClure, Mike wrote:
> >
> > [...]
> > > in a private reply yesterday i suggested this:
> > > "cp argus.log.{[5-9],1[0-9],2[01]}.gz /tmp"
> > >
> > > which doesn't have backticks, pipes or loops.
> >
> > ...and therefore has no chance of winning the "most convoluted 1-line
> > solution".  Really, I don't know why you even bothered :-)
>
> [untested code follows]
>
> target=$(( 21 - 5 ))
> while [ $target != 0 ]
> do
>   averybadnameforavariable=$RANDOM
>   if [ $averybadnameforavariable -lt 22 ]
>   then
>     if [ $averybadnameforavariable -lt 4 ]
>     then
>       if [ -f argus.log.$averybadnameforavariable.gz ]
>       then
>         cp argus.log.$averybadnameforavariable.gz /tmp
>         target=$(( $target - 1 ))
>       fi
>     fi
>   fi
> done
>
> Now, I'll leave putting that on one line for an exercise for the reader.
>
> Cheers,
> Mikal
>
> --
>
> Michael Still (mikal at stillhq.com) | "All my life I've had one dream,
> http://www.stillhq.com            |  to achieve my many goals"
> UTC + 11                          |    -- Homer Simpson
>
>



More information about the linux mailing list