Unix Tip: Using stty to Your Advantage

Be the first to comment | 3I like it!
February 22, 2006, 03:29 PM —  ITworld.com — 

Send in your Unix questions today!


See additional Unix tips and tricks



The stty (set the options for a terminal) command can be very useful once you get the knack of using it. Stty can give you quick manual control over the characteristics of your terminal. If ever you have found yourself working on a terminal in which the terminal settings did not match your actual terminal, you will know how annoying this situation can be. It is often experienced when you attempt to backspace to fix a typo on the command line and, instead of seeing the cursor move backwards on the line erasing characters, you see an increasingly long string of ^H or ^? characters appearing at the end of your command line.


boson> echo "Please send me the lsit^H^H^H


What this tells you is that ^H (control-H) is not functioning as an erase. Using stty, however, you can reset your erase character like this:

boson> stty erase \^h



To see a list of your current stty settings, type the following command:

stty -a



This command will list your current settings in a format like this:


boson> stty -a

speed 38400 baud;

rows = 80; columns = 132; 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



The standard control characters are:

control-d end of file (eof)

control-h backspace (erase)

control-z suspend (susp)

control-u delete text from start of line (kill)

control-c interrupt



The most commonly used stty command is undoubtedly the "stty erase ^h" command which is often used in scripts


if [ `tty | grep -ci console` -eq 0 ]
then
	stty ERASE ^H
	TERM=SUN
fi

You can also display your settings in a format which allows you to restore them at a later time. This is done with the "stty -g" command, the output of which (on one of my Solaris systems) looks like this:


boson> stty -g

2502:1805:f00bf:8a3b:17:1c:7f:15:4:0:0:0:11:13:1a:19:12:f:17:16:0:0:1:1:0:00:0

:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0:0

Sign up for ITworld's Daily newsletter
Follow ITworld on Twitter @IT_world

I like it!
Post a comment
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
peer-to-peer

Esther Schindler
If the comments are ugly, the code is ugly

claird
SVG a graphics format for 21st century

pasmith
Take Chrome OS for a test spin

Sandra Henry-Stocker
Solaris Tip: Have Your Files Changed Since Installation?

sjvn
64-bits of protection?

jfruh
Android fragments vs. the iPhone monolith

mikelgan
What Gizmodo missed about the Pro WX Wireless USB disk drive

 

Sidekick: The Good News & the Bad News
Either way you look at it Microsoft Data Center management did not follow standards or best practices in this failure. In which case it makes me wonder more about the outsourcing of corporate data much less personal data.
- mburton325

Join the conversation here

The Daily Tip

The Daily TipQuick, practical advice for IT pros. Made fresh daily.

Hot tips:

Want to cash in on your IT savvy? Send your tip to tips@itworld.com. If we post it, we'll send you a $25 Amazon e-gift card.

Newsletters

Subscribe to ITWORLD TODAY and receive the latest IT news and analysis.

I would like to receive offers via email from ITworld partners.
By clicking submit you agree to the terms and conditions outlined in ITworld's privacy policy.
Featured Sponsor

AISO founders envisioned a Web hosting company that was environmentally friendly. While the company employed energy-efficient innovations like solar panels, its infrastructure produced unacceptable power and cooling requirements. Find out how AISO leveraged AMD technology to overcome their challenge in this case study white paper.

In this whitepaper, Scalar explores the opportunity to change the landscape with respect to mission critical databases built around Oracle. Leveraging technologies such as Linux, high-end commodity processing power and Oracle RAC technology to architect, design, build and maintain database infrastructure that delivers maximum availability, reliability and performance at a fraction of traditional cost.

On a typical day, weather.com, the Web site for The Weather Channel in Atlanta, serves up between 15 million and 20 million page views. But in September 2004, when back-to-back hurricanes ransacked Florida, the peak traffic on one day more than tripled: over 70 million page views by more than 7 million unique visitors. Read the full success story now.

Marketplace