小编No *_*ame的帖子

shell 脚本中未读取文件的最后一行

我有一个文本文件foo.txt,其中包含以下文本作为内容,

1
2
3
4
5
Run Code Online (Sandbox Code Playgroud)

我有一个 shell 脚本,

file="foo.txt" 
while IFS= read -r line
do
   echo "$line"
done < "$file"
Run Code Online (Sandbox Code Playgroud)

但这仅打印到4.

实际输出:

1
2
3
4
Run Code Online (Sandbox Code Playgroud)

如何获得如下预期输出?

预期输出:

1
2
3
4
5
Run Code Online (Sandbox Code Playgroud)

shell file

3
推荐指数
1
解决办法
2884
查看次数

标签 统计

file ×1

shell ×1