Remove ^C when CTRL+C

Edit (or create) your ~/.inputrc file. Add a line saying

set echo-control-characters Off

This will instruct the GNU Readline library (which Bash uses) to not output (echo) any control characters to the screen. The setting will be active in all new Bash sessions thereafter (and in any other utility that uses the Readline library).

Notice that if your Unix system comes with a system-wide configuration file for the Readline library (usually /etc/inputrc), then your personal configuration file will need to include that file:

$include /etc/inputrc
set echo-control-characters Off

Another alternative is to make a personal copy of the system-wide configuration file and then modify that.


Try the following:

stty -echoctl

For an explanation see this great and detailed post from Stéphane Chazelas which also explains some other stty features.

If you want to make that change permanent (and you are using bash as implied in your question) then it's best to put into your .bashrc as noted by jlmg in the comments (so it applies to all interactive shells).


If you're trying to find a configuration that will allow normal echoing (including echoctl) and just silence the echoing of signal-generating characters, and you're sure it should be possible because you've seen it work that way before...

You probably have seen it that way. But it's no longer possible, because of this commit:

commit ec5b1157f8e819c72fc93aa6d2d5117c08cdc961

Turn on INTR/QUIT/SUSP echoing in the N_TTY line discipline (e.g. ctrl-C will appear as "^C" if stty echoctl is set and ctrl-C is set as INTR).

Linux seems to be the only unix-like OS (recently I've verified this on Solaris, BSD, and Mac OS X) that does not behave this way, and I really miss this as a good visual confirmation of the interrupt of a program in the console or xterm. I remember this fondly from many Unixs I've used over the years as well. Bringing this to Linux also seems like a good way to make it yet more compliant with standard unix-like behavior.

If you remember fondly how Linux used to not echo that ^C, the only way to get the old behavior back is to patch your kernel. In recent versions, the echoing of signal-generating characters is at lines 1215-1218 of drivers/tty/n_tty.c.

Tags:

Shell