[Chapter 5] 5.3 Setting the Terminal Type When You Log In
Author: Jerry Peek, Tim O'Reilly & Mike Loukides
Date: 1998-08-04T21:32:59Z

#

| Chapter 5 Setting Up Your Terminal |

## 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
    setenv TERM vt100

or in your .profile (2.2):

    export
    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):

- If no arguments (1.2) are specified and TERM is already set, tset uses the value of TERM to determine the terminal type.

- If no arguments are specified and TERM is not set, then tset uses the value specified in the system file /etc/ttytype or /etc/ttys (BSD 4.3 and derivatives only).

- If a terminal type is specified as an argument, that argument is used as the terminal type, regardless of the value of TERM.

- The -m (map) option allows a fine degree of control in cases where the terminal type may be ambiguous. For example, if you sometimes log in on a dialup line, sometimes over a local area network, and sometimes on a hardwired line, the -m option can be specified to determine which login is currently being used, and the terminal type can be set accordingly.

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:

`@``speed`

  Means at the specified speed.

`<``speed`

  Means less than the specified speed.

`>``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

5.2 The Idea of a Terminal Database |  | 5.4 Setting the TERMCAP Variable with tset