UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 5.2 The Idea of a Terminal Database Chapter 5
Setting Up Your Terminal
Next: 5.4 Setting the TERMCAP Variable with tset

5.3 Setting the Terminal Type When You Log In

If you always work at the same terminal, there's no problem with setting the terminal type explicitly in your .login file (2.2):

setenv TERM vt100

or in your .profile (2.2):

TERM=vt100; export TERM

But if, like many UNIX users, you might log in from time to time at different terminals, from home, or on different systems over a network, you need some more intelligent method for setting the terminal type.

It's possible to set up various kinds of tests (2.12) in your shell setup files to do this. But you can also do a surprising amount of terminal type testing with tset, even though it was nominally designed for initializing the terminal (5.11):

In the Bourne shell, tset can be used to set the value of TERM as follows:

TERM=`tset - -Q options`; export TERM

(Given the - option, tset prints the value that it determines for the terminal type to standard output (13.1). Otherwise, it initializes the terminal (5.11), but keeps the terminal type to itself. The -Q (quiet) option causes tset to suppress printing of a message it normally prints regarding the values to which it has set the erase and kill characters - a job it does in its alternate role as terminal initializer. The backquotes (9.16) surrounding the tset command cause its output to be interpolated into the command line.)

In the C shell, you should use the eval (8.10) command to capture the output of tset; this will also allow you to set the TERMCAP variable (5.4). (You must also issue the command set noglob, as explained in article 6.9.)

To see what tset can do, consider a case where the terminal's serial line is connected to a dialup modem, through which several different users might be connected, each using a different type of terminal. Accordingly, the default terminal type in /etc/ttytype should be set to dialup. The tset command could then be used in the .login file as follows, with the appropriate terminal type set for each user:

set noglob
eval `tset -s -Q -m 'dialup:vt100'`

This means that if ttytype says dialup, use vt100 as the terminal type. A colon separates the ttytype value and the value to which it is to be mapped. If a user wants to be prompted to be sure, place a question mark after the colon and before the mapped terminal type:

set noglob
eval `tset -s -Q -m 'dialup:?vt100'`

The prompt will look like this:

TERM = (vt100)

If the user presses RETURN, the preferred terminal type will be used. Alternatively, another terminal type could be entered at that time.

You can cause tset to prompt for a terminal type even without testing a generic entry like dialup. Just specify the desired terminal type, preceded by a question mark, after the -m option. For example:

set noglob
eval `tset -s -Q -m '?vt100'`

It is also possible to specify different terminal types for different line speeds. Say, for example, that you normally used a Wyse-50 with a 9600-bps modem when dialing in from home, but used a portable PC with a VT100 terminal emulator and 2400-bps modem when you were on the road. You might then use a tset command like this:

set noglob
eval `tset -s -Q -m 'dialup@2400:vt100' wy50`

Assuming that the type is set in ttytype as dialup, tset will use the type vt100 if at 2400 bps and, if not, will use the type wy50.

[Watch out for the linespeed switches. They don't work on a lot of networked systems - usually, the line speed at the computer's port is higher than the speed at the terminal. The same problem occurs, these days, with dialup modems that use data compression. -JP ] Various symbols can be used for line-speed calculations:


Means at the specified speed.


Means less than the specified speed.


Means greater than the specified speed.

An exclamation point can precede the operator to reverse the sense of the comparison. (For example, !@1200 would mean at any speed other than 1200 bps. In the C shell, you have to type \!@1200 (11.2) instead.)

Multiple -m options can be specified; the first map to be satisfied will be used. If no match is found, a final value specified on the line without a -m option (as in the above example) will be used. If no value is specified, the type in /etc/ttytype will be used.

These changes may not always work; article 42.3 explains why. Article 41.9 has a script for adjusting your terminal.

- TOR from O'Reilly & Associates' termcap & terminfo, Chapter 4

Previous: 5.2 The Idea of a Terminal Database UNIX Power ToolsNext: 5.4 Setting the TERMCAP Variable with tset
5.2 The Idea of a Terminal Database Book Index5.4 Setting the TERMCAP Variable with tset

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System