Please use
[code][/code] tags around your code and data, to preserve formatting and to improve readability. Please do not use quote tags, colors, or other fancy formatting.
Don't Read Lines With For. You should almost always use a
while+read loop instead when working with files or the output of commands.
One possibility it's failing could be line endings. If the file was created on a Windows machine, it will have dos-style
cr+lf line endings, instead of unix-style
lf-only line endings, and the extra carriage return could be messing it up. This is particularly true in an arithmetic context, since anything not an integer would break syntax.
The output of
file will tell you if it has
crlf line endings. If so, there are many options for fixing them, such as
tofrodos. Google or LQ search it.