3 ms·
The Unix and the Echo (2001)
- TedDoesntTalk 6y agoI'd say they overthought the behavior of echo... just a little bit.
- hunter2_ 6y agoIf 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.
- LeoPanthera 6y ago"echo -n" will omit the trailing newline, on both Linux and BSD. echo -n with no other arguments therefore outputs literally nothing. (Except for the "echo" builtin in /bin/sh, which does not recognise -n.)
- teddyh 6y agoDebian GNU/Linux guarantees that the echo builtin, even in /bin/sh, supports the -n option: https://www.debian.org/doc/debian-policy/ch-files.html#scripts https://www.debian.org/doc/debian-policy/ch-files.html#scrip...
- jeffrallen 6y agoEverything2 rocks. I used to be a somewhat prolific noder.
- saagarjha 6y ago> f u cn rd ths u mst uz unix I thought this was cursing at me at first! By the way, if you actually care about your newlines use printf.