End-of-Transmission character: Difference between revisions

Description is now more precise.
m (spelling; person)
(Description is now more precise.)
== Meaning in Unix ==
 
CommonlyIn itcontrast isto believed{{Bythe whom}}DOS that[[control-Z]] <tt>^D</tt>character, iswhich ansignifies end-of-file character in [[Unix-like]]text systemsfiles, similarin toUnix, the DOS [[controlend-Z]].of-file Itscharacter actual(by behaviordefault is toEOT) causecauses the terminal driver to immediately make available anyall characters inits the lineinput buffer, andimmediately; ifnormally the bufferdriver iswould emptycollect to switch to an end-of-file conditioncharacters until it is reset. A <tt>^D</tt> in a file does not mean anything.
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.
 
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 <tt>^D</tt> by typing {{keypress|Ctrl}}+{{keypress|V}} and then {{keypress|Ctrl}}+{{keypress|D}}.
 
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 <tt>^D</tt>EOT by typing {{keypress|Ctrl}}+{{keypress|V}} and then {{keypress|Ctrl}}+{{keypress|D}}.
If the terminal is in "raw" mode then the <tt>^D</tt> character is sent unchanged to the program, which may decide to interpret it as ending the input. This is similar to how MSDOS works, where programs interpret the <tt>^Z</tt> character as ending the input.
 
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.
 
==See also==
Anonymous user