Shell Script to Add Array Elements Using For Loop on Command Line Full Tutorial For Beginners

 

 

numbers.sh

 

 

#sum of array shell script

arr=(10 20 30 40 50)

sum=0

for i in ${arr[@]}
do
    sum=`expr $sum + $i`
done

echo $sum

Leave a Reply