syntax error: invalid arithmetic operator (error token is “”)

后端 未结 1 1716
不知归路
不知归路 2020-12-06 18:55

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

相关标签:
1条回答
  • 2020-12-06 19:22

    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")
    
    0 讨论(0)
提交回复
热议问题