I just started learning shell scripting.
I’m trying to read from a file structured like:
harddrive1 10 20 30 40
harddrive2 20 30 40 50
harddrive3 30 40 50 60
I want to save the average of each row in a separate variable somehow…there will only be 3 rows, 5 columns.
So my output would be:
hd_AVG1=20
hd_AVG2=35
hd_AVG3=45
How can I accomplish that?
EDIT: I need to save it in DIFFERENT variable so that i can call the variable…for example
if [[ $hd_AVG1 -eq 20 ]];
then
do something...
elif [[ $hd_AVG2 -gt 40 ]];
then
do something...
fi
This bash script should do what you want. It calls
bcto do the float arithmetics since bash cannot do it itself.