4 ms·
> Sending Control with a character from the 2nd column is useless. Control clears the 7th bit, but this is already 0, so Control+# will just send “#”. With the
by saurik 4y ago
> Sending Control with a character from the 2nd column is useless. Control clears the 7th bit, but this is already 0, so Control+# will just send “#”.
With the curious exception of Ctrl-?, which turns ON the 7th bit and results in DEL.
- tyingq 4y ago>so Control+# will just send “#” You can get around this with Ctrl-v Like typing, at a shell prompt: echo "<ctrl-v><ctrl-#>"
- mprovost 4y agoBut that still doesn't result in a control character. In my terminal (testing with cat -v) I just get a beep (and it's not a BEL character!). Because the 7th bit of 35 ('#') is already 0 there's nothing to convert it into.
- tyingq 4y agoInteresting, maybe terminal dependent, because it seems to work for me. Piping it to hd shows 7f coming out for <ctrl-?> and 1b for <ctrl-#>. And it works for other things, like: echo "<ctrl-v><esc>c" clears my screen. (where <ctrl-key> means pressing <ctrl>+key, <esc> means pressing the escape key, etc)
- mprovost 4y agoFor my Rust book I've just been diving into the old BSD 4.4 source code for cat which converts control characters into printable ASCII with the -v flag and it handles DEL as a special case: putchar(ch == '\177' ? '?' : ch | 0100). But if you XOR the character with 0100 (64) it always clears the 7th bit, which results in '?' for DEL. Interestingly, peeking at the GNU coreutils code it also handles DEL as a special case and just prints "^?".
- soneil 4y agoDEL's an exception because it had to be all ones. The idea is you can turn any character into a delete character by punching out the rest of the row on a punchcard. Were it any other character, you'd potentially have holes you needed to un-punch.