Live data from Hacker News

What typing ^D does on Unix (2009)

utcc.utoronto.ca

21–30 of 162 posts

Re: What typing ^D does on Unix (2009)

#21
post #3

huh. That's really interesting. I assume ^L is handled in the tty driver as well?

^L usually has no assigned action. $ stty -a | grep -F '^D' intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = ; $ stty -a | grep -F '^L' $ Your Ctrl-L clear-and-refresh command is implemented in Bash (or rather GNU readline). There is a "reprint" action, commonly bound to ^R: $ stty -a | grep rprnt eol2 = ; swtch = ; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; It doesn't clear the screen; it just issues…

And sadly ^t doesn't do the Tenex function of a snapshot of sysstat for the current process.

Re: What typing ^D does on Unix (2009)

#22

Pressing enter then ~. will gracefully shutdown hung ssh sessions

Sadly it will shutdown only the 'outer' ssh session, so if you ssh to foo, and then from foo ssh to bar, and type ~. then the client->foo session is shut down but the foo->bar session is still around.

You need to type one ~ per session level toy want to reach and terminate. In your example, type ~~. to terminate the inner session, leaving the outer one live.

Re: What typing ^D does on Unix (2009)

#23

Pressing enter then ~. will gracefully shutdown hung ssh sessions

Sadly it will shutdown only the 'outer' ssh session, so if you ssh to foo, and then from foo ssh to bar, and type ~. then the client->foo session is shut down but the foo->bar session is still around.

To kill the inner one you need to escape it: ~~. ~? displays the supported escape sequences.

Re: What typing ^D does on Unix (2009)

#25

^U will clear the buffer - super convenient for retrying botched passwords.

In readline, ^U will only clear from the cursor to the start of the line, leaving anything on the right. ^K is the converse.

I'm not sure you are speaking about readline though.

Another very useful thing I use daily is Alt-F/B, to move forward/backward in the line one word at a time. Control does the same, one letter at a time. D will delete an element instead.

Re: What typing ^D does on Unix (2009)

#26

As a corollary, typing ^D twice on a non-empty line will also send EOF on the input, allowing you to provide a program with input not ending with \n from the command line. I knew about this behavior, but not why it worked, but this article's explanation clarifies this behavior as well. The first ^D terminates the read() call, passing the line so far, without terminating \n, to the program. The second causes read() to…

I know this article says Unix specifically, but on Linux (Ubuntu) I just tried typing `ls^D` in bash and got a terminal beep. I tried in zsh and got an autocomplete as if I'd hit tab. In ksh and fish nothing happened. I'm curious as to why there are different behaviors here?

Re: What typing ^D does on Unix (2009)

#27

Earlier quoted context omitted.

^L usually has no assigned action. $ stty -a | grep -F '^D' intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = ; $ stty -a | grep -F '^L' $ Your Ctrl-L clear-and-refresh command is implemented in Bash (or rather GNU readline). There is a "reprint" action, commonly bound to ^R: $ stty -a | grep rprnt eol2 = ; swtch = ; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; It doesn't clear the screen; it just issues…

And sadly ^t doesn't do the Tenex function of a snapshot of sysstat for the current process.

On Linux, you can compile in kernel support for a "Magic SysRq" key which causes SysRq to give you a menu of various debug printing and other actions. It works on serial consoles also, where instead of SysRq, a serial line break signal can map to the action (so it is completely out-of-band relative to serial data).

https://en.wikipedia.org/wiki/Magic_SysRq_key

Re: What typing ^D does on Unix (2009)

#30
post #26

As a corollary, typing ^D twice on a non-empty line will also send EOF on the input, allowing you to provide a program with input not ending with \n from the command line. I knew about this behavior, but not why it worked, but this article's explanation clarifies this behavior as well. The first ^D terminates the read() call, passing the line so far, without terminating \n, to the program. The second causes read() to…

I know this article says Unix specifically, but on Linux (Ubuntu) I just tried typing `ls^D` in bash and got a terminal beep. I tried in zsh and got an autocomplete as if I'd hit tab. In ksh and fish nothing happened. I'm curious as to why there are different behaviors here?

As the article explained at the end, shells put the terminal into uninterpreted mode, so ^D doesn't do anything special there. You have to be using a program (such as cat) that doesn't do this to see ^D's behavior.
Post reply on HN