UNIX Hints & Hacks

ContentsIndex

Chapter 7: Displays and Emulations

 

Previous ChapterNext Chapter

Sections in this Chapter:

   

7.1 Terminal Types

 

7.5 Testing ASCII Terminals

 

7.8 Refreshing X

 

7.11 Control the Mouse with the Keyboard

7.2 Setting Terminal Types

 

7.6 Troubleshooting ASCII Terminals

 

7.9 Killing Resources with xkill

 

7.12 Display from a Remote X Server

7.3 Make Use of stty

 

7.7 Sharing STDIN/STDOUT on Two Terminals

 

7.10 Setting xterm Titlebars

 

7.13 ASCII Table in UNIX

7.4 Hotkeys

 

 

 

 

 

 

 

7.2 Setting Terminal Types

7.2.1 Description

7.2.1 Description

In order to get the proper terminal setting, you need to set your terminal type. The terminal type is set from the environment variable called TERM. The shell is irrelevant as long as it can set the environment variable TERM. The variable can be set in different ways, depending on the shell you use.

Example One: Setting TERM in csh

Flavors: AT&T, BSD

Shell: csh

In csh, the variable is set from the shell prompt or from the .cshrc startup file in the user's home directory.

rocket 2% setenv TERM vt100

An alias entry can be set up for all the terminals that might be used to access the system in the .cshrc file.

rocket 3% vi .cshrc

alias setvt      'set term=vt100'
alias setvt2     'set term=vt220'
alias setansi    'set term=ansi'
alias setxterm   'set term=xterm'

rocket 4% source .cshrc
rocket 5% setvt

rocket 6% echo $TERM
vt100

After the .cshrc has been modified with the terminal type aliases, you can source the .cshrc to make the aliases active. After selecting the appropriate terminal, echo the variable to verify that the new value has been set.

Example Two: Setting TERM in sh or ksh

Flavors: AT&T, BSD

Shells: sh, ksh

The environment variable TERM can be set from the shell prompt or from the .profile startup file.

$ TERM=vt100; export TERM

Aliases are not available, but there is another workaround you can use that will simulate an alias-like feature without using a shell script. Functions are often used in shell scripts to organize and replicate particular steps, but they are not limited to scripts. One nice thing about functions is that they are portable between Bourne shell and Korn shell, as well as their derivatives. The following describes one way that a function can be used.

You can place a function in the .profile file and call it from a shell. The function enables you to change an environment variable quickly and easily.

rocket 7% vi ~/.profile

term()
{
 if [ -z "${1}" ]; then
     echo "Your TERM type is set to $TERM"
 else
     echo "Your TERM was $TERM \c"
     TERM=${1}
     export TERM
     echo "and is now $TERM"
 fi
}

Line 1: Define the function called term.

Line 2: Start of the function.

Line 3: If a there was no terminal type passed to the function, proceed to line 4.

Line 4: Display the current terminal type setting.

Line 5: If the terminal type was passed to the function, proceed to line 6.

Line 6: Display the old terminal type setting.

Line 7: Set the terminal type to the value passed to the function.

Line 8: Make the TERM variable usable to the current shell.

Line 9: Display the new TERM variable setting.

Line 10: Close the regular expression.

Line 11: End of function.

The next time you log in to the system and are dropped into a shell, you can type term to find out the current terminal type.

$ term
Your TERM type is set to vt100

If you want to change the terminal type, pass it through to the term function.

$ term ansi
Your TERM was vt100 and is now ansi

Keep in mind that when you're working with these functions, they run before any commands in the path with the same name. This means that if there is a /usr/local/bin/term, the function term would run first unless you fully qualify the program /usr/local/bin/term to run.

Note - These functions do not carry over to subshells. If you shell out of an application, the function isn't available.


Reason

Every time you connect to the server from a local terminal, the network, or over a modem, you need to set the proper terminal type to make use of all the special features that your terminal has to offer.

Real World Experience

There are certain instances when the terminal setting you select does not work. Even if you have all the proper termcap/terminfo entries, on some occasions the settings don't work across various platforms. These cases are few, but they have been noticed when an xterm or window shell (wsh) session is open on an AT&T system; after the user logs into a remote BSD-type system, the terminal emulation becomes confused. Although simple commands such as clear might work, if you attempt to run the vi editor, the cursor remains at the bottom of the screen instead of at the top.

You have a couple of options when this happens. You should try another terminal type. Most systems offer more than one type of terminal shell in their environments. If you work in a windowing environment, there is xterm, xwsh, and wsh, to name a few. You also can try to exit the windowing environment and drop down to the console level to see whether the console terminal can be emulated correctly.

What you are about to read is not recommended except for those extremely proficient with vi, but if nothing seems to work and you have to edit a file with vi, you can vi the file. You should limit yourself to basic commands such as search, h, l, insert, escape, write, and quit. Always back up the original file before you attempt this and check the file with more or cat to verify that the changes worked.

If you are in a fast-paced environment where you don't have time to mess around with finding the right terminal types, or an emergency occurs where the proper terminal settings are not available, vi can still be used to edit a file. You should test this method now and become comfortable in this mode before you are forced to use it: Set the terminal type to an incorrect terminal and learn how to move around in vi. If you do this, the next time you're in a crunch you won't have to fiddle around with emulation problems. When necessary, use the clear screen (Ctrl+L) command to refresh the screen to verify the current line and changes that have been made. This is not a recommended administrative practice, but it can be done. Also learn the UNIX ed line editor for those times when you are in a bind.

Other Resources

Man pages:

profile, termcap, terminfo, profile

UNIX Hints & Hacks

ContentsIndex

Chapter 7: Displays and Emulations

 

Previous ChapterNext Chapter

Sections in this Chapter:

   

7.1 Terminal Types

 

7.5 Testing ASCII Terminals

 

7.8 Refreshing X

 

7.11 Control the Mouse with the Keyboard

7.2 Setting Terminal Types

 

7.6 Troubleshooting ASCII Terminals

 

7.9 Killing Resources with xkill

 

7.12 Display from a Remote X Server

7.3 Make Use of stty

 

7.7 Sharing STDIN/STDOUT on Two Terminals

 

7.10 Setting xterm Titlebars

 

7.13 ASCII Table in UNIX

7.4 Hotkeys

 

 

 

 

 

 

 

© Copyright Macmillan USA. All rights reserved.