zgoda
zgoda

Reputation: 12895

Stop echoing ^C to terminal

How do I tell my bash to not echo ^C back to terminal?

If I just hit Ctrl+C in bash session, nothing is printed in my terminal window. But if I terminate some program with Ctrl+C, sometimes ^C is echoed and printed in my terminal. Is there any way to tell my bash I do not want echoing back ^C at all?

Upvotes: 11

Views: 3050

Answers (3)

Aesthir
Aesthir

Reputation: 365

You could trap sigint... Put a function into your .bashrc or .profile. Here's my trap on sigint:

Trap2 () ( Tred "%6s–<Interrupt>–\n" ''; return 202 ); trap Trap2 SIGINT
Where Tred is a function which prints red text. If you want nothing displayed, use this:
Trap2 () ( return ); trap Trap2 SIGINT
Cheers!

-- Aesthir

Upvotes: 0

Andy
Andy

Reputation: 871

Under Linux:

stty -ctlecho

(props to Charlie for the hint - I just went and looked it up)

Upvotes: 18

Charlie Martin
Charlie Martin

Reputation: 112356

Well, I believe it's actually echoing "caret"-C, not the CTRL-C character. Other than that, this is actually a function of the tty driver, not the shell; the driver actually intercepts the CTRL-C character, generates a SIGINT to the process, and echos the characters. If there is a way to do it on your system (this will be heavily OS dependent) it would be documented in the stty(1) man page or the tty(4) driver page.

Upvotes: 5

Related Questions