I am working on this code where I redirected a set of 60 numbers into an array and I was wondering if there was a way to get the if statement part to run for all 60 numbers without having to copy and paste the set of if statements and change the embassy value 60 times?
Revision: So to clear up my question here is my is my code and I want to run each number I saved into the array to run through the while loop without having to create an if statement block for each embassy value.
readarray -t score < hw4spr21grades.txt
echo "${score[*]}"
#echo "" "${#score[@]}"
declare y=0
declare A=0
declare B=0
declare C=0
declare D=0
declare F=0
while [ "$y" -le 60 ]
do
if [ "${score[0]}" -le 100 ] && [ "${score[0]}" -ge 90 ]
then
echo "${score[0]}" : 'A' >> hw4spr21output.txt
((y++))
((A++))
elif [ "${score[0]}" -le 89 ] && [ "${score[0]}" -ge 80 ]
then
echo "${score[0]}" : 'B' >> hw4spr21output.txt
((y++))
((B++))
elif [ "${score[0]}" -le 79 ] && [ "${score[0]}" -ge 70 ]
then
echo "${score[0]}" : 'C' >> hw4spr21output.txt
((y++))
((C++))
elif [ "${score[0]}" -le 69 ] && [ "${score[0]}" -ge 60 ]
then
echo "${score[0]}" : 'D' >> hw4spr21output.txt
((y++))
((D++))
elif [ "${score[0]}" -le 59 ] && [ "${score[0]}" -ge 0 ]
then
echo "${score[0]}" : 'F' >> hw4spr21output.txt
((y++))
((F++))
fi
if [ "${score[1]}" -le 100 ] && [ "${score[1]}" -ge 90 ]
then
echo "${score[1]}" : 'A' >> hw4spr21output.txt
((y++))
((A++))
elif [ "${score[1]}" -le 89 ] && [ "${score[1]}" -ge 80 ]
then
echo "${score[1]}" : 'B' >> hw4spr21output.txt
((y++))
((B++))
elif [ "${score[1]}" -le 79 ] && [ "${score[1]}" -ge 70 ]
then
echo "${score[1]}" : 'C' >> hw4spr21output.txt
((y++))
((C++))
elif [ "${score[1]}" -le 69 ] && [ "${score[1]}" -ge 60 ]
then
echo "${score[1]}" : 'D' >> hw4spr21output.txt
((y++))
((D++))
elif [ "${score[1]}" -le 59 ] && [ "${score[1]}" -ge 0 ]
then
echo "${score[1]}" : 'F' >> hw4spr21output.txt
((y++))
((F++))
fi
if [ "${score[2]}" -le 100 ] && [ "${score[2]}" -ge 90 ]
then
echo "${score[2]}" : 'A' >> hw4spr21output.txt
((y++))
((A++))
elif [ "${score[2]}" -le 89 ] && [ "${score[2]}" -ge 80 ]
then
echo "${score[2]}" : 'B' >> hw4spr21output.txt
((y++))
((B++))
elif [ "${score[2]}" -le 79 ] && [ "${score[2]}" -ge 70 ]
then
echo "${score[2]}" : 'C' >> hw4spr21output.txt
((y++))
((C++))
elif [ "${score[2]}" -le 69 ] && [ "${score[2]}" -ge 60 ]
then
echo "${score[2]}" : 'D' >> hw4spr21output.txt
((y++))
((D++))
elif [ "${score[2]}" -le 59 ] && [ "${score[2]}" -ge 0 ]
then
echo "${score[2]}" : 'F' >> hw4spr21output.txt
((y++))
((F++))
fi
done