Live data from Hacker News

What typing ^D does on Unix (2009)

utcc.utoronto.ca

101–110 of 162 posts

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

#101
post #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.

For the vi-adherents out there, `set -o vi` will let you navigate your prompt and history with vi-like keybindings. I'm amazed by how many vi users don't know this.

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

#102

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 asked about this on StackOverflow a few years ago, and got a great answer.

http://stackoverflow.com/questions/15666923/sys-stdin-does-n...

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

#103
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.

For the vi-adherents out there, `set -o vi` will let you navigate your prompt and history with vi-like keybindings. I'm amazed by how many vi users don't know this.

I'm amazed by how many people still run bash!

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

#104
post #91
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.

To add to that, C-P will go up in your history and C-N down. It is extra useful when using GDB in TUI mode (which is activated using C-x,a), which will capture your UP/DOWN arrow to navigate the source... Actually, just go read http://ss64.com/bash/syntax-keyboard.html or something, once per day, integrate a new one each time, and you will improve your productivity on the command line (as well as comfort).

For gdb TUI, you can also use the 'focus cmd' and 'focus src' commands to choose which window gets to handle up/down. I usually keep the command window focused out of habit because the source window intercepts too many keys for my liking.

Nice link - reminds me to try to use the history stuff like ! and ^ more.

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

#105

Neat. So when my terminal is spewing output because I ran "cat massivefile" instead of "cat massivefile | head", I can hit ctrl-D to stop it instead of repeatedly hitting ctrl-C and despairing.

No, thats what ctrl-s and ctrl-q are for.

Here's the rest in one place:

                       eof          VEOF         EOF character
                       eol          VEOL         EOL character
                       eol2         VEOL2        EOL2 character
                       erase        VERASE       ERASE character
                       erase2       VERASE2      ERASE2 character
                       werase       VWERASE      WERASE character
                       intr         VINTR        INTR character
                       kill         VKILL        KILL character
                       quit         VQUIT        QUIT character
                       susp         VSUSP        SUSP character
                       start        VSTART       START character
                       stop         VSTOP        STOP character
                       dsusp        VDSUSP       DSUSP character
                       lnext        VLNEXT       LNEXT character
                       reprint      VREPRINT     REPRINT character
                       status       VSTATUS      STATUS character
cchars: discard = ^O; dsusp = ^Y; eof = ^D; eol = ; eol2 = ; erase = ^?; intr = ^C; kill = ^U; lnext = ^V; min = 1; quit = ^\; reprint = ^R; start = ^Q; status = ^T; stop = ^S; susp = ^Z; time = 0; werase = ^W;

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

#106

Earlier quoted context omitted.

^\ is actually sigquit, which is a bit different from sigkill, since programs can catch QUIT and perform some cleanup.

Also ^| (as in, "control pipe") which is a synonym for ^\. At least for me, | is faster to hit than \ And since we're on this topic: if I write a for loop in bash that runs a slow command 1000 times (ImageMagick comes to mind), and I realise something has gone wrong, is there an easy way of breaking the outer loop?

If you wrote the for loop interactively, you can suspend it with ^Z and kill its jobspec with 'kill %n' (for n usually = 1).

If it's part of a script, your script probably wants to trap SIGINT.

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

#107
post #28

Earlier quoted context omitted.

+++ATH0

How did modems deal with pluses in data? Was there a way to escape the escape sequence, or was there just an ATSnnn or similar sequence to disable escapes?

How did modems deal with pluses in data?

Many years ago, modem maker Hayes Microcomputer Products held a patent dealing with that issue. The clever bit was in looking for

    +++ 
to effect the escape.

Hayes tried to collect royalties, but this caused quite a kerfuffle. Cheap modem makers didn't bother looking for pauses. "Hilarity" ensued. Other solutions were found.

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

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

#108
post #53

Earlier quoted context omitted.

It is also very convenient to remap up/down keys to not just list history, but to do completion based on already typed characters: if [[ $- == *i* ]] then bind '"\e[A": history-search-backward' bind '"\e[B": history-search-forward' fi (fix: grammar)

Debian and Ubuntu typically have a commented-out mapping for this in /etc/inputrc as pgup/pgdn that I always enable in my ~/.inputrc. Editline supports something similar in .editrc IIRC.

Funny, I became FreeBSD user because default .cshrc contained it (iirc). I didn't know about shells, readline, etc. back then. Wonder why they do not enable it on up-down by default, cause I see too many linuxoids around bored with up-up-up-enter up-up-up-enter to replay history, not even knowing that completion exists (along with at least ^K ^U ^C).

What's the point to type a half-command and then replace input line with one from history if I press up? That somewhat resembles ugly cmd.exe, which every windows user imagines when someone says 'cli'.

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

#109

I wish articles like this would say what ^D means. I remember when I was new to Unix it took me a while to realize that I wasn't supposed to type a literal caret (^) followed by a D. For reference it means Ctrl+D, unless you you have a strange keyboard from Sun or something.

Reminds me of how many time I went crazy trying to close a telnet session on memcached ("Escape character is '^]'.") :)

And then imagine trying to escape telnet on an international keyboard (Swedish in my case). Telnet actually kind of works, if you press ctrl+altgr+8 (which is one hell of a hand-twister), but many games and GUIs ONLY allow you to press the listed, with no other modifiers.

So many games don't even allow you to open the console, because they assume that your key next to 1 is ~, and so don't work for § (next to 1) or altgr+¨ (the layout's ~). Or switch between looking at characters or scancodes depending on the context, and thus work in some cases but not all.

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

#110

Earlier quoted context omitted.

Also ^| (as in, "control pipe") which is a synonym for ^\. At least for me, | is faster to hit than \ And since we're on this topic: if I write a for loop in bash that runs a slow command 1000 times (ImageMagick comes to mind), and I realise something has gone wrong, is there an easy way of breaking the outer loop?

> Also ^| (as in, "control pipe") which is a synonym for ^\. At least for me, | is faster to hit than \ How? Do you have a keyboard where | isn't Shift+\?

On a Swedish keyboard, | is altgr+< (between shift and z), and \ is altgr++ (between 0 and ´).
Post reply on HN