But that's a common misconception and not how Ctrl-D works on Unix.
Ctrl-D is part of the terminal discipline and causes an immediate stop
of the current read(2) syscall. If nothing is in the input buffer,
this causes a zero-length read which is detected as end of file.
I once read a Patricia Cornwell novel in which the plot hinged around some
crooked person typing
cat > ttya
Somebody is coming
meaning to send a message to /dev/ttya, but instead, creating a file named
"ttya".
(I almost surely have the details wrong, but I'm too lazy to go searching
for the real quote, which isn't relevant here.)
Cornwell said the ttya file was of size 18, so, being an obsessive
nit-picker, I sent her a letter saying that it could have been 18 bytes
long,
but that would imply that the sender terminated the message with CTRL-D
rather than a newline and then terminating the command,
the latter of which seemed much more plausible for a novice user. Rather
than ignoring my letter, or telling me where to shove my letter,
she sent me a gracious thank you note, and an FBI hat, which I still own.
On Sat, Jul 2, 2022 at 3:37 PM Leah Neukirchen <leah(a)vuxu.org> wrote:
Clem Cole <clemc(a)ccc.com> writes:
On Fri, Jul 1, 2022 at 10:03 AM Steve Nickolas
<usotsuki(a)buric.co>
wrote:
On Fri, 1 Jul 2022, Nelson H. F. Beebe wrote:
Ctrl-D signifies end of transmission. Some other
O/Ses have used
Ctrl-Z for that purpose, presumably because Z is the final letter
of numerous alphabets.
I thought only CP/M and its descendants did that. :o (Of course that
includes DOS and Windows)
Steve - The social disease spread of DOS-11, RT-11, CP/M, and MS/PS-DOS
used ^Z as an EOF character in their text file format. The key is that
they stored a block count, not a byte count in the META. Thus the last
byte needs a marker to tell the OS to stop reading. [Early DEC OS's may
have done that also, but I never looked at their FS formats].
Unix, of course, never made any distinction to the core OS WRT to 'type'
[other than Regular/Directory/Special] and Ken stored a character count.
So there was no need to signal EOF with a markered stored on disk..
A pipe or the shell on the other hand does have a need to signal the end
of
a transaction, and 'End of
Transmission,' as Nelson points out, is the
ASCII character reserved for the same.
But that's a common misconception and not how Ctrl-D works on Unix.
Ctrl-D is part of the terminal discipline and causes an immediate stop
of the current read(2) syscall. If nothing is in the input buffer,
this causes a zero-length read which is detected as end of file.
You can verify this e.g. by typing "foo<Ctrl-D>" into cat(1). It will
print "foo", but not exit. Another Ctrl-D will then quit cat(1) due
to the empty read.
In no case, a ASCII Ctrl-D 0x4 is sent over a pipe or to a shell.
(Over the pty, yes.)
cheers,
--
Leah Neukirchen <leah(a)vuxu.org>
https://leahneukirchen.org/