bash - shell script sum in for loop not working -


size=`ls -l /var/temp.* | awk '{ print $5}'`         fin_size=0         row in ${size} ;                                fin_size=`echo $(( $row + $fin_size )) | bc`;         done echo $fin_size 

is not working !! echo $fin_size throwing garbage minus value. i'm mistaking? (my bash old , suppose work in linux kernel: 2.6.39)

below should enough:

ls -l /var/temp.*  | awk '{a+=$5}end{print a}' 

no need run loop.this means:

size=ls -l /var/temp.* | awk '{ print $5}'`         fin_size=0         row in ${size} ;                                fin_size=`echo $(( $row + $fin_size )) | bc`;         done echo $fin_size 

the whole above thing can replaced :

fin_size=`ls -l /var/temp.*  | awk '{a+=$5}end{printf("%10d",a);}'` echo $fin_size 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -