I need to write a bash script that adds the current values and returns the average. When I run the script ./average I get the error message: missing}. I am not sure why the script isn't printing the average to screen when I run it.
Here's what I have written thus far:
#! /bin/csh
for var in "${sum[store1=100, store2= 75, store3= 74, store4= 100, store5= 100])}"
do
total= $sum(store1+store2+ store3+store4+store5))
echo $sum / 5
done
Fixed: (Updated)
#/bin/bash
total=0
list=(100 75 74 100 100)
for var in "${list[@]}"
do
total=$((total + var))
done
average=$((total/5))
echo $average
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With