Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
为什么建议 shell 脚本以新行结尾?我注意到许多程序员在他们的脚本末尾留下一个空行。是否有特定原因或 POSIX 建议?
在许多情况下,一行被定义为以换行符结尾,因此您可以说通过将其排除在外,您的最后一个“行”不是一行。
按预期工作
$ printf 'foo\n' > bar.txt $ while read; do echo $REPLY; done < bar.txt foo
这里没有输出
$ printf 'foo' > qux.txt $ while read; do echo $REPLY; done < qux.txt