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
Post a Comment