for loops

pefv700 at perv.pe.utexas.edu pefv700 at perv.pe.utexas.edu
Thu Apr 4 14:36:20 AEST 1991


In article <3693 at ux.acs.umn.edu>, edh at ux.acs.umn.edu (Merlinus Ambrosius) writes...
>In sh, I'd like to do something like a BASIC for loop.  Say I have $FILES
>set to some number, and I'd like to go through a loop $FILES times.  Can
>this be done in sh?
> 
>Thanks!
>		--eric

How about either

while [ $FILES -gt 0 ]
do
    # body
    FILES=`expr $FILES - 1`
done

or

i=0
while [ $i -lt $FILES ]
do
    # body
    i=`expr $i + 1`
done

Chris



More information about the Comp.unix.shell mailing list