Bash 缺少文件中的最后一行
示例
C标准指出,文件应以新行结尾,因此,如果EOF位于行尾,则某些命令可能不会忽略该行。举个例子:
$ echo 'one\ntwo\nthree\c' > file.txt $ cat file.txt one two three $ while read line ; do echo "line $line" ; done < file.txt one two
为了确保在上面的示例中该方法正确运行,请添加测试,以便在最后一行不为空的情况下继续执行循环。
$ while read line || [ -n "$line" ] ; do echo "line $line" ; done < file.txt one two three
热门推荐
10 小红书平安祝福语简短
11 生日祝福语大全女孩简短
12 收生日红包祝福语 简短
13 领证幽默祝福语简短
14 法考面试祝福语简短
15 老哥出门祝福语简短语
16 送灯祝福语简短独特
17 幼儿狗年祝福语大全简短
18 好听的元旦简短祝福语