Basic script to calculate the average, asking numbers in the terminal

read Nx
i=0
x=0
while [ $i -lt $Nx ]; do
    read y
    let x=$x+$y
    let i=$i+1
done
result=$x/$i
echo "${result}" | bc -l | xargs printf "%.3f"

By davs

One thought on “Loop in Bash”

Leave a Reply