End-of-Transmission character: Difference between revisions

(Undid revision 375888975 by Alexander.stohr (talk) DOS does not use ^Z or ^D as a signal at all, it is a character)
== Meaning in Unix ==
 
The EOT character in Unix is different from the [[Control-Z]] in DOS. The DOS Control-Z byte is actually sent and/or placed in files to indicate where the text ends. In contrast the Control-D causes the Unix terminal driver to signal the EOF condition, which is not a character, while the byte has no special meaning if actually read or written from a file or terminal.
In contrast to the DOS [[control-Z]] character, which signifies end-of-file in text files, in Unix, the end-of-file character (by default EOT) causes the terminal driver to make available all characters its input buffer immediately; normally the driver would collect characters until
it sees an end-of-line character. If the input buffer is empty (because no characters have been typed since the last end-of-line or end-of-file),
a program reading from the terminal reads a count of zero bytes. In Unix, such a condition is understood as having reached the end of the file.
The terminal driver turns an end-of-line character into a newline (LF) but suppresses the end-of-file character.
 
In Unix the end-of-file character (by default EOT) causes the terminal driver to make available all characters its input buffer immediately; normally the driver would collect characters until it sees an end-of-line character. If the input buffer is empty (because no characters have been typed since the last end-of-line or end-of-file), a program reading from the terminal reads a count of zero bytes. In Unix, such a condition is understood as having reached the end of the file.
An EOT character in a file has no special meaning.
 
This can be demonstrated with the [[cat (Unix)|cat]] program on [[Unix]]-based operating systems such as [[Linux]]: Run the <code>cat</code> command with no arguments, so that it accepts its input from the keyboard and prints output to the screen. Type a few characters without pressing {{keypress|Enter}}, then type {{keypress|Ctrl}}+{{keypress|D}}. The characters you have typed to that point are sent to cat, which then writes them to the screen. If you type {{keypress|Ctrl}}+{{keypress|D}} without typing any characters first, you terminate the input stream and the program ends. You may be able to get an actual EOT by typing {{keypress|Ctrl}}+{{keypress|V}} and then {{keypress|Ctrl}}+{{keypress|D}}.
 
If the terminal driver is in '''raw''' mode it no longer interprets control characters, and the EOT character is sent unchanged to the program, which is free to interpret it any way it likes. A program may then decide to handle the EOT byte as an indication that it should end the text, this would then be similar to how Control-Z is handled by DOS programs.
which is free to interpret it any way it likes.
 
==See also==