APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed
RSS Feeds RSS Feeds











(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Printer Friendly Version
->
-> tput and stty


tput and stty






2013/08/15


Both of these have to do with your terminal. Either can be informational (telling you something about your terminal settings) or active (changing something). For example, "tput" can control the position of the screen cursor:

Try this:

tput clear
echo "hello world"
echo "Input please"
tput cuu1
tput cuu1
tput cuf1
tput cuf1
tput cuf1
tput cuf1
tput cuf1
tput cuf1
tput el
read akey
tput clear
echo Thanks
 

You can look up the things you can do in "man terminfo". For example, "tput clear" will clear the screen, while "tput cols" will tell you how wide your terminal is.

Another useful resource is Colours and Cursor Movement With tput.

On the other hand, stty controls things like "echo". Let's say that you wanted to turn off character echo while reading a password. You could do this:

old=`stty -g`
stty -echo
read password
stty $old
 

Why save the old stty settings? It's so you can put them back to what they were. If you just said "stty echo". you are assuming that's how it was previously set. It might not be: if the script was called from an emacs session, echo would have been off and you would have turned it back on!

You can set colors: Using color in shell scripts (Linux, Mac OS X), switch to a line drawing characer set and much more.

A simple "stty sane" can often restore a garbled screen (see My screen is completely unreadable if that's not enough).

You might also try "tput reset" and "tput init" (which may be indentica;l see "man tput").

You can fix backspace confusion that comes up when telneting from Linux to SCO:

   case $TERM in
        ""|unknown|dumb|dial*|tty|*ansi*)
            TERM=ansi
            ;;
        linux|xterm|rxvt)
            stty intr '^c'
            stty erase '^?'
            tput smpch
            ;;
    esac
    export TERM
 

(From Problem with backspace key when telnet from Linux)

A common confusion for folks unfamiliar with SCO is that, by default, SCO systems set interrupt to the DELETE key, not CTRL-C. If you find that unbearable, you can easily change it; for example,

 stty intr ^C
 

will change your interrupt on Bourne or Korn shells. In this example, you actually type CTRL-C; if you are in vi adding it to your .profile, type CTRL-V and then CTRL-C

This can also be added to .profile (or whatever startup file your shell uses) or to /etc/profile.

We'd use stty "hold-open" scripts to control settings on serial printers also.

Flow control is also controlled by stty. That's often needed for serial sevices, but even on virtual terminals you can pause output with Cntrl-S and (if stty ixany is set), restart it with any keystroke.

Should you happen to be using a serial terminal for some reason, Linux Serial How-To may be helpful. Real serail terminal or not, "stty -a" will display its settings:

$ stty -a
speed 9600 baud; 35 rows; 119 columns;
lflags: icanon isig iexten echo echoe -echok echoke -echonl echoctl
tony@Ant-echoprt -altwerase -noflsh -tostop -flusho pendin -nokerninfo
tony@Ant-extprocac:~$ 
iflags: -istrip icrnl -inlcr -igncr ixon -ixoff ixany imaxbel iutf8
	-ignbrk brkint -inpck -ignpar -parmrk
oflags: opost onlcr -oxtabs -onocr -onlret
cflags: cread cs8 -parenb -parodd hupcl -clocal -cstopb -crtscts -dsrflow
	-dtrflow -mdmbuf
cchars: discard = ^O; dsusp = ^Y; eof = ^D; eol = <undef>;
	eol2 = <undef>; erase = ^?; intr = ^C; kill = ^U; lnext = ^V;
	min = 1; quit = ^\; reprint = ^R; start = ^Q; st
 

The 9600 baud is meaningless unless you really are on serial.

Serial Wiring and Communications for the Confused might also be useful if you find yourself dealing with some ancient serial system.

See also Terminfo Capabilities and Termcap and Terminfo.





If this page was useful to you, please help others find it:  





Comments?




More Articles by - Find me on Google+



Click here to add your comments
- no registration needed!


Don't miss responses! Subscribe to Comments by RSS or by Email

Click here to add your comments


If you want a picture to show with your comment, go get a Gravatar

Kerio Samepage


Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.

Publishing your articles here

Jump to Comments



Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.

I am a Kerio reseller. Articles here related to Kerio products reflect my honest opinion, but I do have an obvious interest in selling those products also.

Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.

We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.

pavatar.jpg

This post tagged:

       - Basics
       - Linux
       - MacOSX
       - Terminals
       - Unix















My Troubleshooting E-Book will show you how to solve tough problems on Linux and Unix systems!


book graphic unix and linux troubleshooting guide



Buy Kerio from a dealer
who knows tech:
I sell and support

Kerio Connect Mail server, Control, Workspace and Operator licenses and subscription renewals



Click and enter your name and phone number to call me about Kerio® products right now (Flash required)