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 红包祝福语简短10字
18 周六早晨祝福语简短