Live data from Hacker News

What typing ^D does on Unix (2009)

utcc.utoronto.ca

81–90 of 162 posts

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

#81
post #30
post #26

Earlier quoted context omitted.

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.

Actually bash (by default) does do something special with ^D: it's mapped to the "delete-the-char-after-the-cursor" functionality (just like the DEL key is), by analog to the delete-char binding in emacs.

But indeed, it's in raw mode so the kernel doesn't do anything special and just emits the 0x04 byte down the descriptor.

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

#82
post #45

Earlier quoted context omitted.

It's not about neutrality, it's about ease of understanding. For me at least, when speaking about something that can be entered into a keyboard ^D is less obvious than Ctrl+D–I need to press the key labeled "control" to issue the proper command, the key labeled "^" will not suffice.

To be really pedantic (sorry! I'm not complaining about your comment), your keyboard does not have any key labelled 'control', it is always (AFAIK) abbreviated as 'ctrl'. Which is really weird to me, as it's hardly a big word needing abbreviating, and keyboards often have other long words written on the keys ('delete', 'page down', and so on). On top of that, the shortened 'ctrl' is really a terrible abbreviation. It…

http://www.clickwithyourmac.com/wp-content/uploads/2014/01/C...

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

#83

Earlier quoted context omitted.

To be really pedantic (sorry! I'm not complaining about your comment), your keyboard does not have any key labelled 'control', it is always (AFAIK) abbreviated as 'ctrl'. Which is really weird to me, as it's hardly a big word needing abbreviating, and keyboards often have other long words written on the keys ('delete', 'page down', and so on). On top of that, the shortened 'ctrl' is really a terrible abbreviation. It…

You're incorrect, especially for the typical reader here. A good chunk (maybe not over 50%, but its gotta be close) of the regular readers on this site use Macs. Most Mac keyboards, including the ones on the Macbook Pro, spell it out. Same for most non IBM/IBM-PC compatible keyboards.

I'm typing on a MacBook Pro that has "ctrl".

Not sure I've ever seen a Mac keyboard that said "control", but maybe that's because I've mostly seen Finnish keycaps.

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

#87
post #3

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

An important upshot is that TTY I/O never actually ends; EOF from a TTY is a temporary condition, and input can continue. In the C standard library, you just clearerr(stdin) and keep reading. If a program takes two files as input and obeys the - convention for specifying stdin (or has some other way of opening the tty more than once), you can do: $ program - - then give it two inputs, each followed by [Ctrl-D][Enter]…

You can work around this with other shell trickery. This might work in your shell:

    $ program 
The program itself isn't involved in opening the TTY / reading from it, etc, that is all handled by your shell before fork/execing program. program doesn't know that any of these shenanigans have happened.

It probably uses more memory (the shell has to have both stdin's in memory before it can exec the program), but overall I have mostly abandoned trying to use '-' as an input because of the way some tools, perhaps less-steeped in unix-y traditions, don't honor it correctly.

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

#88
post #40
post #25

Earlier quoted context omitted.

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.

There's a lot of unexpected gems in the readline defaults. I recommend people try paging through "bind -p" in bash some time to see what's there. Personal favorites are C-r to search back in history and C-x C-e to edit the current command line in an external editor.

Ah! yes, at this point C-r is so entrenched in my habit, I didnt even realize it might be new to some.

This is the shortcut to first learn when starting living in the command line.

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

#89

Earlier quoted context omitted.

^D is the old school way of writing it; you'd see it so much you'd only ever once be confused about it, generally in the very first few days you were learning to use a computer. It's never used anymore, I suppose, except for the old school people who still have enough muscular memory built up to write it that way. I know I do; I learned it from some computer magazine in the 80's and have a hard time letting go.

It's used when talking about text editors a fair bit.

More than just text editors, it is used system wide in OS X menus to describe the available shortcuts.

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

#90
post #83

Earlier quoted context omitted.

You're incorrect, especially for the typical reader here. A good chunk (maybe not over 50%, but its gotta be close) of the regular readers on this site use Macs. Most Mac keyboards, including the ones on the Macbook Pro, spell it out. Same for most non IBM/IBM-PC compatible keyboards.

I'm typing on a MacBook Pro that has "ctrl". Not sure I've ever seen a Mac keyboard that said "control", but maybe that's because I've mostly seen Finnish keycaps.

Look in the menu bars and you'll only see ^ describing the shortcuts.
Post reply on HN