Sorting 3 columns and getting the average

后端 未结 1 1596
渐次进展
渐次进展 2021-01-21 11:20

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)
             


        
1条回答
  •  后悔当初
    2021-01-21 12:00

    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
    

    0 讨论(0)
提交回复
热议问题