如果我在输入末尾按 C-d
,输入似乎被刷新,但没有 EOF
发送到程序。但是,如果我再按一次 C-d
,就会发送 EOF
。
为什么我第一次按 C-d
时没有发送 EOF?这种行为记录在哪里?
为了试验自己玩 cat
,这里有一个例子:
$ cat
abc<C-d>abc<C-d>
$
最佳答案
C-d
是 End-of-transmission (EOT) character :
In Unix the end-of-file character (by default EOT) causes the terminal driver to make available all characters in 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.
在您的示例中,当您运行 cat
并键入几个字符后跟 C-d
时,此时键入的字符将发送到 cat
将它们打印到屏幕上。现在输入缓冲区为空,因此当您再次键入 C-d
时,cat
从缓冲区读取零字节并终止,因为已满足文件结束条件。
关于Bash:C-d 的真正作用是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13838986/