LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 05-26-2010, 09:53 AM   #1
Skaperen
Senior Member
 
Registered: May 2009
Location: WV, USA
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,185
Blog Entries: 21

Rep: Reputation: 151Reputation: 151
Ctrl-C to echo ^C or not


I've noticed that in some distributions, or even some versions of distributions, pressing Ctrl-C at the bash command prompt either results in ^C being echoed, or not. I've been looking in "man bash" for a setting that would affect that (it doesn't apply when outside of bash, so I presume it is just something bash does or has set) but cannot find it. Anyone know what to do in bash to change this? If it matters, I want to turn it off where it is on.
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 05-27-2010, 03:44 AM   #2
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,075

Rep: Reputation: 1433Reputation: 1433Reputation: 1433Reputation: 1433Reputation: 1433Reputation: 1433Reputation: 1433Reputation: 1433Reputation: 1433Reputation: 1433
I think this behavior can be controlled with the stty command. Perhaps there is something in the bash startup scripts that is toggling an option.

Cheers,

Evo2.
 
Old 05-27-2010, 04:41 AM   #3
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198
Quote:
Originally Posted by evo2 View Post
I think this behavior can be controlled with the stty command.
I thought so too, netsearched for how and experimented a little but did not come up with an answer. I have noticed that when a script or a loop entered at the command prompt is running and Ctrl+C is used, then ^C is displayed.
Code:
c@CW8:~$ while true; do sleep 1; done
^C
 
Old 06-01-2010, 09:12 AM   #4
Skaperen
Senior Member
 
Registered: May 2009
Location: WV, USA
Distribution: Xubuntu, Ubuntu, Slackware, Amazon Linux, OpenBSD, LFS (on Sparc_32 and i386)
Posts: 2,185

Original Poster
Blog Entries: 21

Rep: Reputation: 151Reputation: 151
I just tried running bash under strace to see if bash (or some library linked into its process) was really the culprit. See the 6th line:

Code:
read(0, 0x7fffddc44e9f, 1)              = ? ERESTARTSYS (To be restarted)
--- SIGINT (Interrupt) @ 0 (0) ---
rt_sigreturn(0x2)                       = -1 EINTR (Interrupted system call)
rt_sigprocmask(SIG_BLOCK, [INT], [], 8) = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
write(2, "^C", 2)                       = 2
ioctl(2, TCXONC, TCOON)                 = 0
rt_sigprocmask(SIG_BLOCK, [INT], [], 8) = 0
ioctl(0, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig -icanon -echo ...}) = 0
ioctl(0, SNDCTL_TMR_STOP or TCSETSW, {B38400 opost isig icanon echo ...}) = 0
ioctl(0, SNDCTL_TMR_TIMEBASE or TCGETS, {B38400 opost isig icanon echo ...}) = 0
 
Old 01-04-2011, 02:52 PM   #5
lavajoe
LQ Newbie
 
Registered: Jan 2011
Posts: 2

Rep: Reputation: 3
Quote:
Originally Posted by catkin View Post
I thought so too, netsearched for how and experimented a little but did not come up with an answer. I have noticed that when a script or a loop entered at the command prompt is running and Ctrl+C is used, then ^C is displayed.
Code:
c@CW8:~$ while true; do sleep 1; done
^C
There are a couple of different situations here. If you hit the interrupt character while a program is running, the Linux kernel tty driver will echo "^C" (assuming you are using the default setting of "stty intr", which is ^C) if "stty echoctl" is set. Note that this did not work before kernel 2.6.25, so depending on the version in your Linux distro, you may or may not see this fix (but make sure you have "stty echoctl" set, or you will not see "^C" in any case).

If you hit ctrl-C on the bash command line, however, it is bash's readline code that will echo "^C". This is new bash behavior was introduced in bash 4.0. In bash 4.1, a setting was added to control this readline feature: "echo-control-characters". So putting "set echo-control-characters off" in your .inputrc file will suppress "^C" echo on the bash command line (if using bash 4.1 or later).

-Joe

Last edited by lavajoe; 01-04-2011 at 10:54 PM.
 
3 members found this post helpful.
Old 01-04-2011, 10:40 PM   #6
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198Reputation: 1198
Welcome to LQ lavajoe

Thank you for the very lucid and complete explanation.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Recognizing ctrl+c,ctrl+l,ctrl+d in C programs leonardo6023 Programming 1 08-19-2009 10:23 AM
KDE 3.5.9 - Konqueror - keyboard shortcuts ctrl+, and ctrl+. sometimes stop working bhy Linux - Desktop 1 07-26-2008 12:48 PM
Any way to create bash short cuts (like CTRL+l for clear and Ctrl+D for exit) supersubu123 Linux - General 5 05-30-2007 04:02 AM
ls | echo, I got blank, why can't echo take the 2nd seat in a pipeline? elinuxqs Linux - Newbie 6 11-24-2006 09:25 AM
echo out CTRL- sequences how to? jamesps Linux - General 0 07-22-2005 05:16 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration