when I run my testing.sh file
#!/bin/bash
FILE=$1
COUNT=0
while read -r SID FIRST LAST S1 S2 S3
do
SUM=$(expr $S1 + $S2 + $S3)
AVG=$(expr $SUM / 3)
Your S3
does not actually contain a value such as 90
, but instead contains values such as 90$'\r'
, because your input file has CRLF (DOS) rather than LF (UNIX) newlines. This most often happens if you got your input file from a non-UNIX system.
Fix the file, using tools such as dos2unix
or the vim command :set fileformat=unix
, or use code akin to the following in your script:
S3=${S3%$'\r'} # remove any trailing $'\r' from S3