Afficher un message
Vieux 22/08/2006, 13h32   #4
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to skip small files in a for loop

thomasriise wrote:
> I e.g. have this script:
>
> ---------------------------------
> #!/bin/ksh
>
> numfiles=`ls fil* | wc -w | sed 's/ *//'`
> files=`ls fil*`
> echo "there are $numfiles files to process"
>
> doit(){
> for i in $files
> do
> list=`ls -ut $i`
> size=`ls -lut $i 2>/dev/null | awk '{print $5}'`
> if [ $size -lt 630 ]
> then
> done
> fi
> echo $list
> done
> }
>
> doit
> ---------------------------------
>
> My shell reports that the done in line 15 is unexpected. Is there
> another way to skip the files smaller than the specified size? Or
> should I just do that before the loop should begin?
>
> Thanks.
>


Instead of negative logic:

if [ $size -lt 630 ]
then
# break out of loop
fi
echo $list

just use positive:

if [ $size -ge 630 ]
then
echo $list
fi

By the way, your script will fail for files whose names contain white
space. See question 14,
http://home.comcast.net/~j.p.h/cus-faq-2.html#14, in the FAQ.

Regards,

Ed.
  Réponse avec citation
 
Page generated in 0,06403 seconds with 9 queries