Taking Control of ^h (control-h)

For what seemed like years, I put up with having to type ^h (control h) to back up over mistakes in my typing on one of the many systems on which I have an account. When I was intently typing and found that I was creating strings of ^? characters instead of backing up over the errors, my screen would look like this:

> echo VOTE wise;y^?^?^c
> echo VOTE wisely!
VOTE wisely

Of course, many people like to use ^h as their backspace sequence because ^h will work just about anywhere and, if you become accustomed to using this key sequence to back over mistakes, you don't have to think about it. Your fingers just seem to know what to do even if your mind has wandered away. All my other accounts are set to use the backspace key, though, so I was naturally inclined to press the familiar key and growl quietly when I didn't get the response I expected. In fact, I would often just ^c and start my command over again. I finally admitted to myself that this was stupid. The stty settings are not all that troublesome. I should easily be able to set my erase function to its normal setting.

The "trick" is to fiddle with your terminal settings using the stty command. The "stty -a" command will show you what your current stty settings are. Here's a typical display:

# stty
speed 38400 baud; -parity
rows = 24; columns = 80; ypixels = 0; xpixels = 0;
swtch = <undef>;
brkint -inpck -istrip icrnl -ixany imaxbel onlcr tab3
echo echoe echok echoctl echoke iexten

Some of the settings shown here are clearly tied to your display. We can see that the screen is set to 24 rows and 80 columns. This is all very typical. Some of the other displayed settings are:

brkint		signal interrupt on break
-inpck		disable input parity checking
-istrip		do not strip inpu characters to seven bits
icrnl		map CR to NL on input

Wow, there's a lot more going on here than whether your typing fits into the screen, but here's one you can wrap your brain around. The echo setting determines whether the text you type is echoed in your terminal window. Turn it off with "stty -echo" and all you'll see will be the output of the commands you type. That could come in handy at times, but I'm sure it would confuse a lot of people if they inadvertently invoked this command. You can turn echoing back on with "stty echo".

Most stty settings will be set up reasonably by default. Few users make changes to their stty settings unless they run into some kind of display problem. If your columns variable was set to 40, for example, your man pages and file listings (using "ls") would look very odd, but you could issue a subsequent "stty columns 80" command to set things right.

In this more detailed setup, the erase function has been assigned to ^h (see the 6th line in the output). We can also see some familiar command line options -- like the ^z we use to suspend a process. You could change this to ^x if you were so inclined by issuing the

command "stty susp ^x" or putting this command into your .profile or other start up file.

> stty -a
speed 38400 baud;
rows = 24; columns = 80; ypixels = 0; xpixels = 0;
csdata ?
eucw 1:0:0:0, scrw 1:0:0:0
intr = ^c; quit = ^\; erase = ^h; kill = ^u;
eof = ^d; eol = <undef>; eol2 = <undef>; swtch = <undef>;
start = ^q; stop = ^s; susp = ^z; dsusp = ^y;
rprnt = ^r; flush = ^o; werase = ^w; lnext = ^v;
-parenb -parodd cs8 -cstopb -hupcl cread -clocal -loblk -crtscts -crtsxoff -parext
-ignbrk brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl -iuclc
ixon -ixany -ixoff imaxbel
isig icanon -xcase echo echoe echok -echonl -noflsh
-tostop echoctl -echoprt echoke -defecho -flusho -pendin iexten
opost -olcuc onlcr -ocrnl -onocr -onlret -ofill -ofdel tab3

If your erase setting is set to ^h and you prefer to use your backspace key, you can use the "stty erase ^?" command. That's a lot less trouble than typing ^c and starting over. I should be ashamed of myself for not implementing this fix in my .profile a long time ago!

This article is published as part of the IDG Contributor Network. Want to Join?

Computerworld's IT Salary Survey 2017 results
Shop Tech Products at Amazon