That's how the "EOF" character works (in "canonical" mode input, which is the default). It's actually never sent to the application, so it would be more accurate to call it the EOF
signal.
The EOF
character (normally Ctrl-D) causes the current line to be returned to the application program immediately. That's very similar to the behaviour of the EOL
character (Enter), but unlike EOL
, the EOF
character is not included in the line.
If the EOF
character is typed at the beginning of a line, then zero bytes are returned to the application program (since the EOF
character is not sent). But if a read
system call returns 0 bytes, that is considered an end-of-file indication. So at the beginning of a line, an EOF
will be treated as terminating input; anywhere else, it will merely terminate the line and so you need two of them to terminate input.
For more details, see the .Posix terminal interface specification.