让我们运行cat
然后输入a
then ^D
- 你会看到cat
没有退出。
与cat
+ a
+ Enter
+比较^D
- 现在 cat 确实退出了。
那么,为什么在第一种情况下^D
需要按两次退出cat
,而^D
在第二种情况下只需要按一次?
cam*_*amh 25
答案可以在termios(3)
手册页中找到:
VEOF (004, EOT, Ctrl-D) End-of-file character (EOF). More precisely:
this character causes the pending tty buffer to be sent to the
waiting user program without waiting for end-of-line. If it is
the first character of the line, the read(2) in the user program
returns 0, which signifies end-of-file. Recognized when ICANON
is set, and then not passed as input.
Run Code Online (Sandbox Code Playgroud)
第一个^D
你按下使你键入要传递到线cat
,所以它得到read(2)
的结果a
(一个字符,没有EOL字符)。第二个^D
原因read(2)
返回 0,这表示 EOF 到cat
。
归档时间: |
|
查看次数: |
807 次 |
最近记录: |