[clug] Shell glob for a range of numbers?

Michael Still mikal at stillhq.com
Fri Jan 9 02:34:06 GMT 2004


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