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?

后端 未结 7 797
臣服心动
臣服心动 2020-12-02 13:58

Let’s say I have the following Bash script:

while read SCRIPT_SOURCE_LINE; do
  echo \"$SCRIPT_SOURCE_LINE\"
done

I noticed that for files

相关标签:
7条回答
  • 2020-12-02 15:01

    Instead of read, try to use GNU Coreutils like tee, cat, etc.

    from stdin

    readvalue=$(tee)
    echo $readvalue
    

    from file

    readvalue=$(cat filename)
    echo $readvalue
    
    0 讨论(0)
提交回复
热议问题