I have a problem whenever I add more than 3 numbers with multiple operators. (I tried expr, bc,
SUM=$(( $S1 + $S2 + $S3 ))
and many other forms, but whenever I have 3 variables I get this error.
expr: non-integer argument
expr: syntax error
This is when I do it with 2 variables (works fine)
#!/bin/sh
FILE=$1
while read -r SID FIRST LAST S1 S2 S3
do
SUM=$(expr $S1 + $S2)
AVG=$(expr $SUM / 3)
printf '%d [%d] %s, %s\n' "$AVG" "$SID" "$LAST" "$FIRST"
done < "$FILE" | sort
and when I do 3 variables (doesn't work)
#!/bin/sh
FILE=$1
while read -r SID FIRST LAST S1 S2 S3
do
SUM=$(expr $S1 + $S2 + $S3)
AVG=$(expr $SUM / 3)
printf '%d [%d] %s, %s\n' "$AVG" "$SID" "$LAST" "$FIRST"
done < "$FILE" | sort
expr: non-integer argument
expr: syntax error
txt file
123456789 Lee Johnson 72 85 90
999999999 Jaime Smith 90 92 91
888111818 JC Forney 100 81 97
290010111 Terry Lee 100 99 100
199144454 Tracey Camp 77 84 84
299226663 Laney Camp 70 74 71
434401929 Skyler Camp 78 81 82
928441032 Jess Forester 85 80 82
928441032 Chris Forester 97 94 89