5 ms·
If you have a file consisting of some text, the file might or might not end with a \n If you have a file consisting of some lines of text, the file will end wi
by hunter2_ 6y ago
If you have a file consisting of some text, the file might or might not end with a \n
If you have a file consisting of some lines of text, the file will end with a \n because a line of text (unlike text generally) is typically defined by matching ^[^\n]*\n
Therefore, `echo` with no arguments returns a line of text which contains nothing.
- charlysl 6y agoI think you are right, it is a matter of convenience, to type less, as the story hints, but not only for writing to files, also for displaying messages on the console. According to the book quoted in the link: Since a command should by default execute its most commonly used function, ... echo appends the final newline automatically. It may seem insignificant, but this story highlights, in nerd humour, some of the design philosophy behind Unix. Classic Kernighan (as the book's co-author).
- LeoPanthera 6y agoNotably, reading lines of text with bash's "while read" will skip the last line if the last line does not end in \n.