I am trying to write a function the checks a text file, line by line, checking each field by certain cretirias, and then sums it all up. I am using the exact same way to sum
Your input file contains CR+LF line endings. As such, the variable ${line[4]}
isn't a number like 10
but 10\r
which causes the error.
Remove carriage returns from the input file using a tool such as dos2unix
.
Alternatively, you could change your script to handle it by modifying
done < "$1"
to
done < <(tr -d '\r' < "$1")