2 ms·
I would argue CTRL+D is the right way since it works in almost all shells, and I am surprised not more people know it.
by jeltz 8y ago
I would argue CTRL+D is the right way since it works in almost all shells, and I am surprised not more people know it.
- majewsky 8y agoCtrl+D has a learning curve because its default meaning (i.e. when you're not messing with termios) is quite surprising. From `man tcsetattr`: > VEOF (004, EOT, Ctrl-D): End-of-file character (EOF). More precisely: this character causes the pending tty buffer to be sent to the waiting user program without waiting for end-of-line. If it is the first character of the line, the read(2) in the user program returns 0, which signifies end-of-file. Recognized when ICANON is set, and then not passed as input. In other words, most programs that exit upon Ctrl+D never see the Ctrl+D, they see an empty result from read() on stdin and interpret that as end-of-file. However, that only works when the tty buffer is empty. Try this: On a Unix shell, run `cat`, type something without pressing Enter, then press Ctrl-D instead.