Function SUM SIZE

Dear Friends,

I wrote a script that get the size of specific files in a specific space directory. To get the total size I wrote a function in that script.
So far I am not convinced that function is working correctly.

Do you mind tell if there is anything wrong.

I am on SOLARIS (KSH)
The default size of the files are on Ko

 #------------------------------------------------------
sum_taille () {

   size_koctet=$1
   if [ $size_koctet -gt 1073741824 ]
   then
      ((size=$size_koctet /1024 /1024 /1024))
       unite="Tera"
   else 
    if [ $size_koctet -gt 1048576 ]
       then
          ((size=$size_koctet /1024 /1024))
          unite="Go"
    else
        if  [ $size_koctet -gt 1024 ]
        then
        ((size=$size_koctet /1024))
              unite="Mo"
        fi
       fi
   fi
   echo "$size $unite"
}
#------------------------------------------------------

Thanks in advanced for your help

this may help

du -hc file1 file2 ... 

Dear johnbach,

This cannot help me as all files listed are not on the same directory, and I am talking about more than 10.000 files.

Thanks anyway for your help

fns()
{
arr[0]=KB
arr[1]=MB
arr[2]="GB"
arr[3]="TB"

   sz=$1
   ctr=0;
   while [ sz -gt 1023 ]
      do
         ((sz=$sz /1024.0))
         ((ctr=$ctr +1))
      done
   echo "Size="$sz" "${arr[$ctr]};
}
fns $1

Dear johnbach,

I just wanted to say thank you for your help. The function is working fine..

Thanks again :slight_smile: