Bash:C-d 的真正作用是什么?

标签 bash readline

如果我在输入末尾按 C-d,输入似乎被刷新,但没有 EOF 发送到程序。但是,如果我再按一次 C-d,就会发送 EOF

为什么我第一次按 C-d 时没有发送 EOF?这种行为记录在哪里?

为了试验自己玩 cat,这里有一个例子:

$ cat
abc<C-d>abc<C-d>
$

最佳答案

C-dEnd-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/

相关文章:

bash - 解析日志文件的最佳方式

regex - 在 bash 中删除文本文件中的单个元素

javascript - 为什么我不能在 Nodejs v10 中读取 "import * as readline from ' readline'"?

c++ - while(getline(myReadFile, temp, ':' )) 执行一次迭代太多导致 vector 越界

python - 提取 = 和 ; 之间的整数

c - 如何将 readline 历史记录保存在文本文件中并在之后调用它

bash - OS X Sublime Text3 使用 zsh shell

mysql - 在 Bash 备份脚本中删除旧的 MySQL/MariaDB 备份

linux - bash 中的安全递归删除

java - 在 Java 中使用 readlines 时忽略标签