Please look at ascii table to see why ctrl-{key} sends a corresponding control code and why the modifier is called “control”: https://www.commfront.com/pages/ascii-chart
The article explained it well enough. Makes sense, I just was unaware. From that chart though then could ^` generate a NULL byte?
Re:Getting the ^D
by proto_lambda on Monday April 10, 2023 @02:58AM
(#35509834)
The chart also lists the control key combination for each control byte, for NUL, it's C-@.
^` works too.
If EOF was a character, you couldn't process (binary) streams that contain the character.
^@ produces the NUL character.
Re:Getting the ^D
by 1vuio0pswjnm7 on Monday April 10, 2023 @04:02AM
(#35510155)
"I am curious now, would it be possible to make the keyboard generate a NULL byte either by existing keyboard shortcut or custom hardware - and how would the system handle it?"
Not sure I understand the point of the experiment, but in NetBSD kernel one can remap the keyboard, e.g., set a key to 0x00. How to do this in Linux kernel is a question for reader.
https://ftp.netbsd.org/pub/NetBSD/NetBSD-current/src/sys/dev...
The NUL byte has no special meaning in file I/O, or the terminal. (Historically, the only special meaning was as a no-op character that does nothing.) The convention of using NUL as a termination character only exists for in-memory strings in C, and has no connection to file I/O.
Sending a special EOT 0x4 that gets special terminal handling feels just a little less… elegant… than what I had imagined.