Afficher un message
Vieux 22/08/2006, 16h55   #8
Stephane Chazelas
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: How to skip small files in a for loop

On 22 Aug 2006 04:25:31 -0700, 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"



Ouch. That's ugly. If you're using ksh, you could as well use
its extensions. Like arrays.

set -A files -- fil*
printf "there are %d files to process\n" "${#files}"

> doit(){
> for i in $files


for i in "${files[@]}"

> do
> list=`ls -ut $i`


What's that for?

> size=`ls -lut $i 2>/dev/null | awk '{print $5}'`

size=`ls -lut -- "$i" 2>/dev/null | awk '{print $5; exit}'`

What is the -t for?

What about -u as you're only interested in the size.

> if [ $size -lt 630 ]


if [ "$size" -lt 630 ]

> then
> done


continue instead of done

> fi
> echo $list


printf '%s\n' "$i"


> done
> }


This script would more reasonably be written:

find . \( -name . -o -prune \) -name 'fil*' \! -size -630c -print

Note zsh's:

print -rl fil*(^L-630)

--
Stephane
  Réponse avec citation
 
Page generated in 0,04768 seconds with 9 queries