The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 04-23-2009
lavascript lavascript is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 47
I'd do something like this (in ksh):-


Code:
foundc=0
nfoundc=0

for file in $FILELIST
do
   if [[ -s "${file}" ]];then
       # file is found and is > 0 bytes.
       foundc=$(( found + 1 ))
       ...do something else you want...
   else
       # file is not found or is 0 bytes
       nfoundc=$(( nfounc + 1 ))
       ...do something else you want...
   fi
done

print "number of files in [$FILELIST] found = [${foundc}]\n"
print "number of files in [$FILELIST] NOT found = [${nfoundc}]\n"
You can change the -s test for -r (file is readble) -e (file exists) -d (file is directory etc) as you see fit.