Shell Script to Find Average of n Numbers on Command Line Full Tutorial For Beginners

 

 

numbers.sh

 

 

 

#shell script to find average of n numbers
  
echo "Enter Size(N)"
read N

i=1
sum=0

echo "Enter Numbers"
while [ $i -le $N ]
do
  read num               #get number
  sum=$((sum + num))     #sum+=num
  i=$((i + 1))
done

avg=$(echo $sum / $N | bc -l)

echo $avg

Leave a Reply