Why should text files end with a newline?

后端 未结 18 1245
栀梦
栀梦 2020-11-21 22:56

I assume everyone here is familiar with the adage that all text files should end with a newline. I\'ve known of this \"rule\" for years but I\'ve always wondered — why?

18条回答
  •  再見小時候
    2020-11-21 23:32

    Some tools expect this. For example, wc expects this:

    $ echo -n "Line not ending in a new line" | wc -l
    0
    $ echo "Line ending with a new line" | wc -l
    1
    

提交回复
热议问题