Reading input files by line using read command in shell scripting skips last line

前端 未结 5 554
日久生厌
日久生厌 2020-12-01 09:51

I usually use the read command to read an input file to the shell script line by line. An example code such as the one below yields a wrong result if a new line isn\'t inser

5条回答
  •  不知归路
    2020-12-01 10:09

    DONE=false
    until $DONE
    do
      read line || DONE=true
      echo $line
    done < blah.txt
    

    How to use `while read` (Bash) to read the last line in a file if there’s no newline at the end of the file?

提交回复
热议问题