CONTENTS

Chapter 5. Getting the Most out of Terminals, xterm, and X Windows

5.1 There's a Lot to Know About Terminals

This chapter covers most of what you need to know to set up your terminal or terminal emulator from your shell setup files (Section 3.3).

In the latter half of the chapter, we cover the ins and outs of working with some of the most popular terminal-emulator software for the X Window System, including xterm, rxvt, and others, where applicable. The list of terminals and emulators you might come into contact with is long and getting longer, though, so the advice we give in the first section of the chapter regarding how to configure your terminal will be helpful. As you find yourself suddenly confronted with the prospect of configuring the terminal emulator on your cell phone or tablet computer, remember: you can usually make it work, with enough time and effort.

It is important to remember, however, that the tricks and tips we discuss in this chapter, if implemented incorrectly, may cause your terminal to hang. One way around a hung terminal is always to keep at least one other terminal emulator window, with sane settings, open all the time you're modifying the setup of the other. That way, if you hang up the terminal you're actively modifying, you can always go back to the other and save yourself. On systems that support virtual consoles, such as Linux, you can also use command keys (e.g., ALT and the first five function keys) to switch between various virtual consoles, just as you might with a terminal emulator. Don't just reach for the power switch!

—TOR and SJC

5.2 The Idea of a Terminal Database

In the past few years, terminals have been standardized to a few types. In fact, most terminals nowadays are terminal emulators (like xterm) that simulate a terminal on a graphical display. Years ago, though, terminals differed widely. Rather than simply being implemented in software, they were hardware — keyboards and monitors or even teletypes, with which the user interacted to communicate with an often faraway mainframe or other big iron. All were specialized, and differences between them often came down to how much you paid and to what manufacturer. This lets you take advantage of other features of the manufacturer's primary hardware — the big computers they considered their main product. Manufacturers produced a variety of terminals, each one including a particular set of features for a certain price. There were smart terminals and dumb ones, terminals with big screens and terminals with small screens, printing terminals and video displays, and terminals with all sorts of special features.

Differences between terminals do not matter much to programs like cat (Section 12.2) or who (Section 2.8) that use the terminal screen as a sort of typewriter with an endless scroll of paper. These programs produce sequential output and do not make use of the terminal's special features; they do not need to know much to do their job. Only programs such as screen editors, which make use of screen-handling features, need to know a lot about differences between terminals.

However, even today, we find a wide variety of terminal emulators across a multitude of platforms. My new Kyocera Smartphone, for example, is a Palm device integrated with a PCS telephone; one of the main reasons I bought it was for remote, emergency ssh access to my servers, using a tiny terminal emulator that runs on the PalmOS. Many Unix programs assume a basic environment that this terminal emulator does not provide — an 80-column screen — so even simple commands such as w, which prints a list of who is logged in, where they logged in from, and what they're currently running, become impossible to run. But let's go back to the early days and revisit some of the old problems that plagued early Unix developers, so that we might better understand how to deal with today's problems.

In the late 1970s, Bill Joy created the vi (Section 17.2) text editor at UC Berkeley. Like all screen-oriented editors, vi uses the terminal screen nonsequentially (in stark contrast to earlier editors such as ed, which were designed for a teletype, and so use even more terse commands and feature even more terse output). A program performing nonsequential output does not just print character after character, but must manipulate the text that was sent before, scroll the page, move the cursor, delete lines, insert characters, and more. While it would be possible to keep redrawing the screen in its entirety, many features are provided in hardware or firmware by the terminal itself, saving too much time and trouble to be ignored.

The first version of vi was written specifically for Lear Siegler ADM3a terminals. vi was such an improvement over line-oriented editors that there was great demand to port vi to other brands of terminals. The problem was that each terminal had different features and used different control codes to manipulate the features that they did have in common.

Rather than write separate terminal drivers for each terminal type, Bill Joy did something very clever, which all Unix users now take for granted. He wrote a version of vi with generic commands to manipulate the screen instead of hardcoding the control codes and dimensions for a particular terminal.[1]

Joy came up with a generic terminal-handling mechanism that had two parts: a database describing the capabilities of each of the terminals to be supported and a subroutine library that allows programs to query that database and make use of the capability values it contains. Both the library and the database were given the name termcap, which is short for terminal capabilities.

At this point, users take for granted that you can use just about any terminal with a Unix system and use screen-oriented programs like vi without any problem. But this is really quite remarkable!

The termcap database is contained in a single text file, which grew quite large over the years to include descriptions of hundreds of different terminals. To improve performance, AT&T later introduced a database called terminfo, which stores terminal descriptions in compiled form in a separate file for each terminal.

If a program is designed to use termcap or terminfo, it queries an environment variable called TERM to determine the terminal type (or terminal type being emulated), then looks up the entry for that terminal in the terminal database, and reads the definition of any capabilities it plans to use as external variables. Programs that use termcap or terminfo range from screen editors like vi and emacs (Section 19.1), which use the complete terminal description, to a program like clear, which needs to know only one capability (the escape sequence to clear the screen). Other programs include more, pg, rogue, tset (Section 5.3), ul, and nroff.

—JS and SJC

5.3 Setting the Terminal Type When You Log In

If you always work at the same terminal or use the same terminal emulator, there's no problem with setting the terminal type explicitly in your shell setup file (Section 3.3) — like .login or .profile. Just set the TERM environment variable (Section 35.3):

setenv TERM vt100           ...csh, tcsh
TERM=vt100; export TERM     ...sh, ksh, zsh
export TERM=vt100           ...pdksh, bash, zsh

In fact, on a hardwired terminal, your terminal type may already have been set in a system file like /etc/ttys or /etc/ttytype (Section 3.15). 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 may need some more intelligent method for setting the terminal type. To find out, try logging in at each place and starting a screen-oriented program like vi. Do various operations: scrolling up, inserting text that wraps onto another line, deleting lines. If the screen scrambles or the cursor gets "out of sync," your terminal type may need to be set.

It's possible to set up various tests (Section 3.10) 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:

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

export TERM=`tset - -Q options`           ...newer shells
TERM=`tset - -Q options`; export TERM     ...all shells

(Given the - option, tset prints the value determined for the terminal type to standard output (Section 43.1). Otherwise, it initializes the terminal (Section 5.3), but keeps the terminal type to itself. The -Q (quiet) option causes tset to suppress printing a message it normally prints regarding the values set for the erase and kill characters — a job it does in its alternate role as terminal initializer. The backquotes (Section 28.14) surrounding the tset command interpolate its output into the command line.)

In the C shell, you should use the eval (Section 27.8) command to capture the output of tset; this will also allow you to set the TERMCAP variable (Section 35.5). (You must also issue the command set noglob.) To simplify the rest of this article, we'll show examples for the C shell; if you don't use a C-type shell, please translate to Bourne-shell syntax (as shown earlier).

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 or /etc/ttys 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. Alternately, 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. For example, say 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 on the road.[3] 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 /etc/ttys or /etc/ttytype as dialup, tset will use the type vt100 if at 2400 bps and, if not, will use the type wy50. See the tset(1) manual page for more choices. Watch out for the line-speed 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 with dialup modems that use data compression. The stty command will tell you what data rate the system believes you're using.

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 previous example) will be used. If no value is specified, the type in /etc/ttytype or /etc/ttys will be used.

—TOR and SJC

5.4 Querying Your Terminal Type: qterm

tset (Section 5.3) is a powerful tool to use if you often log in at different terminals. You can use tset to prompt you with a default terminal type, giving you the opportunity to specify a new terminal type when you log in:

TERM = (vt100)

However, tset requires you to know your terminal type. You might log in at a new terminal and have no idea what to set the terminal type to. Or your terminal might be configured to emulate another terminal type without your knowledge. New users in particular are confused by the tset prompt. In some respects, this is not a surprise, as the prompt itself can be confusing without a bit of context.

figs/www.gif Go to http://examples.oreilly.com/upt3 for more information on: qterm

As an alternative, try Michael Cooper's qterm program on our CD-ROM [see http://examples.oreilly.com/upt3]. qterm sends the terminal a test string and determines what sort of terminal you're using based on how the terminal responds. Using qterm, you can make sure you always use the correct terminal type by placing the following line in your .login:

'...' Section 28.14

setenv TERM `qterm`

or in .profile:

TERM=`qterm`;export TERM

The advantage of qterm is that it sets the terminal type without your intervention. You don't need to know your terminal type; it gets set automatically.

qterm works by sending the terminal a query string and returning the terminal type depending on the terminal's response. qterm is configured using a listing of responses and the terminals to which they correspond. By default, qterm looks for the listings in a system-wide location such as /usr/local/lib/qtermtab. In addition, you can call qterm with the +usrtab option, so that it will look for a file called .qtermtab in your home directory.

The string used to query the terminal is usually ESC Z. The sample qtermtab file distributed with qterm defines the responses several different terminals give for that string:

#
# QtermTab - Query terminal table for qterm.
#
#SendStr ReceiveStr         TermName       FullTermName
#
^[Z     ^[[?1;0c            vt100          Base vt100
^[Z     ^[[?1;1c            vt100          vt100 with STP
^[Z     ^[[?1;2c            vt100          ANSI/VT100 Clone
   ...
^[Z     ^[/K                h29            Zenith z29 in zenith mode
^[Z     ^[/Z                vt52           Generic vt52
^[Z     ^[[0n               vt100          AT&T Unix PC 7300

If your terminal isn't listed here, you can just add it. To find out your terminal's response to the query string, just echo ESC Z to your terminal and see what the response is. For example, I logged in from my Macintosh terminal emulator at home and found that qterm didn't recognize my terminal type:

% qterm
Terminal NOT recognized - defaults to "vt100".
vt100

qterm defaults to the right terminal description, but I'd still rather define my own entry. I find out my terminal's response to the ESC Z string:

% echo "^[Z"
^[[E;Y|

(Note that ESC prints as ^[.) Then I add the entry to my qterm description file:

^[Z         ^[[E;Y|         vt100       Macintosh terminal emulator

Now when I run qterm, the terminal is recognized:

% qterm
Terminal recognized as vt100 (Macintosh terminal emulator)
vt100

The string Terminal recognized as ... is sent to standard error (Section 43.1); only the terminal type itself is sent to standard output (Section 43.1). So if you use the following command line:

% setenv TERM `qterm`
Terminal recognized as vt100 (Macintosh terminal emulator)

the TERM variable is set correctly:

% echo $TERM
vt100

Now for the caveat: qterm's results are only as accurate as the qtermtab file. Not all terminals respond to the ESC Z string, and you may not find a string to which it responds uniquely. And some terminals do uncanny imitations of others. For example, I'm currently using an xterm (Section 24.20) window, but qterm thinks I'm using a vt100:

% echo $TERM
xterm
% qterm
Terminal recognized as vt100 (ANSI/VT100 Clone)
vt100

As a hack, you can just edit your .qtermtab file. For example, I could comment out the old vt100 entry and map ^[[?1;2c to xterm instead:

#^[Z     ^[[?1;2c            vt100          ANSI/VT100 Clone
^[Z     ^[[?1;2c            xterm          xterm window

and then call qterm with the +usrtab command-line option:

setenv TERM `qterm +usrtab`

—LM and SJC

5.5 Querying Your xterm Size: resize

When the xterm client is called, it not only sets the TERM environment variable, but it also adjusts the terminal definition for the size of the window being created. The size of xterm windows, however, can be changed later on by using the window manager. If the window is resized, then the user's shell may need to be passed the new size information as well, or programs that use termcap and terminfo won't work correctly. The resize client is provided for redefining the number of lines and columns for the terminal database used in an xterm window. Note that resize cannot be used for terminal emulators other than xterm (except for those, like rxvt, that emulate xterm) because it depends on xterm's escape sequences.

Some systems can send a "window size changed" signal (SIGWINCH) to programs and do not require resize to be run for a resized xterm window. We recommend using resize only if terminal-based programs start to have problems with your window size. A typical terminal-based program that is having problems with the window size will fill only some of the lines in the window — or may scroll lines down the window when it shouldn't.

The resize client is typically used immediately after the dimensions of an xterm window are changed. A peculiarity of the resize client is that it does not access the shell itself, but simply returns the shell commands that would be needed; to have those commands read by the shell, you either save its output in a file and read the file with the shell commands source or . (Section 35.29), or evaluate resize output using the shell command eval (Section 27.8). For example, after resizing a window, you would type in that shell:

`...` Section 28.14

% eval `resize`

When you call the resize command under a termcap system, it produces the commands for resetting the TERMCAP environment variable with the li# and co# capabilities reflecting the current dimensions. When you call the resize command under a terminfo system, it produces the commands for resetting the LINES and COLUMNS environment variables.

The resize command consults the value of your SHELL environment variable and generates the commands for setting variables within that shell. If you're using a nonstandard shell, resize may still recognize your shell; as of X Release 5, resize recognizes tcsh, jcsh, ksh, bash, and jsh. But if resize does not recognize your shell, try using the -c or -u options to force resize to use C- or Bourne-shell syntax (respectively), depending on which syntax is appropriate for your shell.

—LM, EP, and SJC

5.6 Checklist: Terminal Hangs When I Log In

If your terminal seems to "hang" (freeze, lock up) when you log in, here are some things to try:

Here are a few more tips for dealing with stuck terminals.

5.6.1 Output Stopped?

If your terminal has a HOLD SCREEN or SCROLL LOCK button, did you accidentally press it? Try pressing it and see if things start working again. If pressing the button once doesn't fix the problem, you should probably press it once more to undo the screen hold. Otherwise, you may lock up your session worse than it was before!

Another way to stop output is by pressing CTRL-s. The way to restart stopped output is with CTRL-q — try pressing that now. (Unlike a SCROLL LOCK button, though, if CTRL-q doesn't help, you don't need to undo it.)

5.6.2 Job Stopped?

If you're at a shell prompt instead of in the program you thought you were running — and if your Unix has job control — you may have stopped a job. Try the jobs command (Section 23.1); if the job is stopped, restart it.

5.6.3 Program Waiting for Input?

The program may be waiting for you to answer a question or type text to its standard input.

If the program you were running does something that's hard to undo — like removing files — don't try this step unless you've thought about it carefully.

If your system has job control, you can find out by putting the job in the background with CTRL-z and bg. If the job was waiting for input, you'll see the message:

[1]  + Stopped (tty input)  grep pat

You can bring the job back into the foreground and answer its question, if you know what that question is. Otherwise, now that the job is stopped, you can kill it. See the following directions.

On systems without job control, you might satisfy the program by pressing RETURN or some other key that the program is expecting, like y or n. You could also try pressing CTRL-d or whatever your "end of input" character is set to. That might log you out, though, unless you've set the ignoreeof variable.

5.6.4 Stalled Data Connection?

Be sure that the wires haven't come loose.

If you're using a modem and the modem has function lights, try pressing keys to see if the Send Data (SD) light flashes. If it does, your terminal is sending data to the host computer. If the Receive Data (RD) light flashes, the computer is sending data to your terminal. If you don't see anything, there might be something wrong on your terminal.

If you're connected with rlogin or telnet or ssh (Section 1.21), the network to the remote computer might be down or really slow. Try opening another connection to the same remote host — if you get a response like Connection timed out, you have two choices:

  1. Wait for your original connection to unfreeze. The connection may come back and let you keep working where you left off. Or the connection may end when rlogin, telnet, or ssh notices the network problem.

  2. Quit the session, and try again later.

5.6.5 Aborting Programs

To abort a program, most users press CTRL-c. Your account may be set up to use a different interrupt character, such as DELETE. If this doesn't work, try CTRL-\ (CTRL-backslash). Under most circumstances, this will force the program to terminate. Otherwise, do the following:

  1. Log in at another terminal or window.

  2. Enter the command ps x, or, if that doesn't work, use ps -u yourname, where yourname is your Unix username. This displays a list of the programs you are running, something like this:

    % ps x
    PID     TTY     STAT    TIME    COMMAND
    163     i26     I       0:41    -csh (csh)
    8532    i26     TW      2:17    vi ts.ms
    22202   i26     S       12:50   vi UNIXintro.ms
    8963    pb      R       0:00    ps -x
    24077   pb      S       0:05    -bin/csh (csh)
    %
  3. Search through this list to find the command that has backfired. Note the process identification (PID) number for this command.

  4. Enter the command kill PID (Section 24.12), where PID is the identification number from the previous step. If that doesn't work, try kill -1 PID to send a HUP signal. You can also try various other signals, including -2 or -15. If none of them work, you may need kill -9, but try the other kills first.

  5. If the Unix shell prompt (such as % or $) has appeared at your original terminal, things are probably back to normal. You may still have to take the terminal out of a strange mode though.

    If the shell prompt hasn't come back, find the shell associated with your terminal (identified by a tty number), and kill it. The command name for the C shell is csh. For the Bourne shell, it is sh. In most cases, this will destroy any other commands running from your terminal. Be sure to kill the shell on your own terminal, not the terminal you borrowed to enter these commands. The tty you borrowed is the one running ps; look at the previous example and check the TTY column. In this case, the borrowed terminal is TTY pb.

    Check ps to ensure that your shell has died. If it is still there, take more drastic action with the command kill -9PID.

  6. Run ps x or ps -u yourname again to be sure that all processes on the other tty have died. (In some cases, processes will remain.) If there are still processes on the other tty, kill them.

  7. At this point, you should be able to log in again from your own terminal.

The ps (Section 24.5) command, which lists some or all of the programs you are running, also gives you useful information about the status of each program and the amount of CPU time it has consumed.

—JP and SJC

5.7 Find Out Terminal Settings with stty

figs/www.gif Go to http://examples.oreilly.com/upt3 for more information on: stty

It may hardly seem appropriate to follow Chris Torek's learned article about how stty works with some basics, but this book is designed for beginners as well as those who already know everything. :-) [Good idea, Tim. This is also a handy place to put the globe icon for the GNU version. ;^) — JP]

So, to find out what settings your terminal line currently has, type:

% stty

For a more complete listing, type:

% stty -a

On older BSD-style systems, use stty everything instead. On most newer BSD-derived systems, stty everything and stty -a are both supported, but with slightly different output formats. The former prints a tabular layout, while the latter prints each control character setting in a name = value format.

As Jerry Peek said in an editorial aside to Chris's article, be sure to have your stty manual page handy!

—TOR and SJC

5.8 Setting Your Erase, Kill, and Interrupt Characters

Have you ever sat down at a terminal where the "erase" key (the character that deletes the last thing you typed) wasn't where you thought it would be? If you have, you know how disorienting this can be! On Linux, there's loadkeys. If you're using the X Window System, check into the xmodmap (Section 5.1) command. Newer shells, like bash and zsh, tend to do their own handling of these special characters — especially during their built-in command-line editing (Section 30.14). Check your shell's manual page about readline. The most portable method is with the stty (Section 5.7) command. All of these give you a way of changing the erase character (along with several others) so you can restore some order to your world.

stty takes two kinds of input. If you want to give the command interactively, type stty erase char, where char is the key you normally use for erase — BACKSPACE, DELETE, whatever — followed by RETURN. This will do the trick, provided that the character you type isn't already used for something. If the character is in use or if you're putting stty commands into your .login, .profile, or .bash_profile file, it's better to "spell these characters out." "Control" characters in .login are allowed, but they aren't a great idea. If you like to use the BACKSPACE key as the erase key, add the following line:

stty erase ^h

If you want to use the DELETE key, quote the ? character so the shell won't treat it as a wildcard (Section 1.13):

stty erase ^\?

That is, stty lets you represent a control key with the two-character combination ^x, where ^ is the literal key ^ (caret) and x is any single character. You may need to put a \ before the x to prevent the shell from interpreting it as a wildcard [and a \ before the ^ to prevent old Bourne shells from interpreting it as a pipe! — JP].

Of course, you're not limited to the BACKSPACE or DELETE keys; you can choose any other key you want. If you want to use "Z" as your DELETE key, type stty erase Z. Just make sure you never want to type a real Z!

Table 5-1 lists functions that stty can change.

Table 5-1. Keys to set with stty

Character

Function

Good setting

See article

erase

Erases the previous character.

^\? (DELETE)

Section 5.8

kill

Erases the entire line.

^u (CTRL-u)

Section 5.8

werase

Erases the previous word.

^w (CTRL-w)

Section 5.8

intr

Terminates the current job.

^c (CTRL-c)

Section 24.11

quit

Terminates the current job; makes a core file.

^\ (CTRL-\)

Section 24.11

susp

Stops the current job (so you can put it in the background).

^z (CTRL-z)

Section 23.3

rprnt

Redisplays the current line.

^r (CTRL-r)

Section 28.2

The command stty everything (BSD derivatives) or stty -a (Linux and System V derivatives) shows all your current terminal settings. The werase and rprnt characters aren't implemented on some older versions of Unix, though they are on Linux and Darwin and most other modern Unix variants.

It's amazing how often you'll see even moderately experienced Unix users holding down the BACKSPACE or DELETE key to delete a partially completed command line that contains an error.

It's usually easier to use the line-kill characters — typically CTRL-u or CTRL-x. (The command stty -a or stty everything (Section 41.3) will tell you which. Section 5.7 shows how to change them.) The line-kill character will work on a command line (at a shell prompt (Section 4.1)) and in other places where the terminal is in cooked mode. Some Unix programs that don't run in cooked mode, like vi, understand the line-kill character, too.

Even better, many stystems have a "word-erase" character, usually CTRL-2, which deletes only back to the previous whitespce. There's no need to delete the entire command line if you want to change only part of it!

As a historical note, the erase character was originally #, and the kill character was originally @. These assignments go back to the olden days, when terminals printed with real ink on real paper and made lots of noise. However, I'm told that there are some modern systems on which these settings are still the default.[5]

Terminal emulators, editors, and other programs can fool around with all of this stuff. They should be well behaved and reset your terminal when you leave them, but that's often not true. So don't expect your settings to work within a terminal emulator; they may, or they may not. And don't expect your settings to be correct after you exit from your terminal emulator. Again, they may, or they may not. This is primarily due to the fact that some terminal-emulator programs lie about the extent to which they support a given set of control codes.

The tset program also fools around (Section 5.3) with key settings. Therefore, in your shell setup files (Section 3.3), put stty after tset.

—ML, JP, SJC, and TOR

5.9 Working with xterm and Friends

xterm is by far the most commonly used X client, although more and more people are switching from xterm to similar or related programs, such as rxvt — which is a lightweight xterm derivative without the Tektronix terminal emulation support. Regardless, the most commonly used clients are largely derivatives of xterm, so we're devoting the rest of this section to this single client and its family.

xterm[6] gives you a window containing your standard shell prompt (as specified in your /etc/passwd entry). You can use this window to run any command-line-oriented Unix program or to start additional X applications.

The uncustomized xterm window should be sufficient for many users' needs. Certainly you can do anything in a vanilla xterm window that you can from a character-based terminal. But xterm also has special features you can use, and since you spend so much time in xterm, you might as well use them.

The rest of this chapter gives you a set of tricks and tips about using xterm, including the following:

The articles in this chapter use terms that you may want defined:

  • A pointer, or pointing device, is a piece of hardware designed for navigating a screen. Most people use a mouse as their pointer, but there are also trackballs, touchpads, and others.

  • The best pointer to use with X has three buttons. When we refer to the first button or button 1, we mean the button you click with your index finger. For right-handed people, this is usually the left button on a mouse. But the X client xmodmap (Section 6.1) lets left-handed users swap mouse buttons to make the rightmost button the "first."

  • Even though the actual image on the screen is called a cursor, throughout this chapter we refer to "moving the pointer" to avoid confusion with the standard text cursor that can appear in an xterm window.

—LM, VQ, and SJC

5.10 Login xterms and rxvts

If you want your xterm or rxvt to run a login shell (Section 3.4), give it the -ls flag, or put a line like one of the following in your X resource file (Section 6.5):

xterm*loginShell: true  ...for xterm
XTerm*loginShell: true  ...for xterm or rxvt
Rxvt*loginShell:  true  ...for rxvt

Once you've defined the appropriate resource, you can get a nonlogin shell (which is otherwise the default) with xterm +ls.

—JP and SJC

5.11 Working with Scrollbars

The scrollbar is a favorite xterm feature, particularly among those whose terminals lacked the ability to scroll backwards. Using the scrollbar, you can re-examine the output or error from a command, select previous text to supply in another command line or to paste into a file, or to hide your current screen from a nosy coworker.

There are many ways to start up the scrollbar. You can specify the -sb option on the command line:

% xterm -sb &
% rxvt -sb &

or you can set the scrollBar resource (Section 6.5) to true:

XTerm*scrollBar:    true  ...for xterm or rxvt
Rxvt*scrollBar:            true  ...for rxvt

or for an xterm window that's already running, you can call up the VT Options menu (Section 5.17) by holding down the CTRL key and the center mouse button or by selecting Enable Scrollbar. These menus are not supported by rxvt.

A scrollbar appears on the left side of the xterm window, as shown in Figure 5-1.

Figure 5-1. xterm window with scrollbar

figs/upt3_0501.gif

—LM and SJC

5.12 How Many Lines to Save?

If you use the scrollbar in xterm (Section 5.11), you'll find that by default the scrollbar retains only 64 previous lines of text. You can change this by using the -sl command-line option:

% xterm -sb -sl 200 &
% rxvt -sb -sl 200 &

or by setting the saveLines resource:

XTerm*saveLines: 200

You don't want to go crazy with the number of saved lines, though. Too many lines saved may crunch on virtual memory and also make it hard to scroll.

—LM and SJC

5.13 Simple Copy and Paste in xterm

You can use the pointer to select text to copy and paste within the same xterm window or between xterm windows. You don't need to be in a text editor to copy and paste. You can also copy or paste text to and from the command line, between the command line and a file, etc.

There are several ways to select (copy) text; all require you to use the pointer. You can select a passage of text, or you can select text by individual words or lines.

When you select text, it is highlighted and copied into global memory from which you can paste it into any xterm window. Regardless of the number of xterm windows you're running, you can store only one selection in memory at a time. However, you can paste that selection as many times as you like. When you make another selection, the new text replaces the previous selection in memory.

Table 5-2 summarizes all of the text-selection methods.

Table 5-2. Button combinations to select text for copying

To select

Do this

Passage

Click the first button at the start of the selection and the third button at the end of the selection. Or at the beginning of the selection, hold down the first button; drag the pointer to the end of the desired text; release the button.

Word

Double-click the first button anywhere on the word.

Line

Triple-click the first button anywhere on the line.

To clear the highlighting, move the pointer off the selection, and click the first button anywhere else in the window. Note, however, that the text still remains in memory until you make another selection.

Of the two methods for selecting a passage, the first is generally easier. Hypothetically, you can select a passage of any length; in practice, we've found there to be limitations. The size of the window limits the amount of text you can highlight in one action. You can extend a selection beyond the parameters of a window. Copying an extremely long selection, however, doesn't seem to work reliably. Also, when pasting a long selection, the text can become garbled.

You can paste text into any xterm window, either onto the command line or into a text file you're editing. In both cases, move the pointer into the window, and click the second button. The text will be pasted; in other words, it will appear on the screen, just as if you typed it.

To paste into an open text file, the editing program must be in insert mode. (If not, when pasted, the selection may be interpreted as a stream of editor commands, such as in vi. The act of pasting the word "selection" in a vi editor not in insert mode would be to ignore everything up until the i, which would place vi into insert mode, and then the last three letters would be inserted into the buffer.)

—VQ and SJC

5.14 Defining What Makes Up a Word for Selection Purposes

You probably already know how to select text (Section 5.13) in an xterm, and you've probably discovered that double-clicking Section 5.13 will select the entire word around the pointer. What you may not know is that it is possible to change what defines a "word."

xterm maintains a table of all the ASCII characters and their character classes. Any sequence of adjacent characters of the same class is treated as a word. Numbers, letters, and the underscore are in class 48 (which is the ASCII code for the character 0) and SPACE and TAB are in class 32 (the ASCII code for SPACE). By default, all the other characters are in classes by themselves.

For Unix users, this isn't the most useful default; it would be better if you could select filenames, email addresses, URLs, resource specifications, etc. as single words even though they often contain punctuation characters.

You can modify the character class table with xterm's charClass resource variable (Section 6.3). The value this resource accepts is a comma-separated list; each item on the list is an ASCII character code or range of characters, followed by a colon, followed by the character class to which the character should be added. I set the charClass resource as follows:

xterm*charClass: 33:48, 37:48, 42:48, 45-47:48, 63-64:48, 126:48

This tells xterm to treat !, %, *, -, ., /, ?, @, and ~ as characters of the same class as numbers and letters. You may also want to treat : as a member of this class, for URLs; in that case, use the following charClass string:

xterm*charClass: 33:48, 37:48, 42:48, 45-47:48, 58:48, 63-64:48, 126:48

—DJF and SJC

5.15 Setting the Titlebar and Icon Text

Under most modern window managers, most windows (including xterm) are displayed with a titlebar. You can change the text in the titlebar using the following xterm escape sequence:

^[ ]2;string^G

Note that this sequence has a close bracket (]) following the ESC (Escape, ^[) — not an open bracket. It ends with a CTRL-g character — not a caret followed by a "g".

I use this sequence to display my current working directory and directory stack in the titlebar, where they are visible but unobtrusive. I do this by adding a few lines to my shell setup file (Section 3.3). Section 4.8 explains.

If you change the number "2" in the escape sequence to "1," it will set the text that appears in the xterm's icon instead of its titlebar. If you change it to "0," it will set the text for both the icon and the titlebar. If you use and iconify a number of xterms, you may find these sequences useful.

You may also wish simply to specify an icon name and/or title text for a given window, statically, for those situations where the window is only used to display output from some program, and not for interactive use. Both xterm and rxvt allow this, using the -n option to specify the icon name and the -T option to specify the title. You may also use X resources to specify icon name or title.

The Mac OS X Terminal application lets you set the title from the Set Title command on the Shell menu as well.

—DJF and SJC

5.16 The Simple Way to Pick a Font

X font names make the Rosetta Stone look like bedtime reading. Those hardy souls who want to experiment with fonts or access fonts on remote machines must take the high road and learn the X font naming conventions anyway. But if you just want to locate some fonts to use with xterm and other clients, you can use the predefined aliases for some of the constant-width fonts available on most systems.

Figure 5-2 lists the aliases for some constant-width fonts that should be appropriate for most of the standard clients, including xterm. [These "aliases" are basically font names. They aren't the same as shell aliases (Section 29.1). Also note that terminals should use constant-width fonts (where every character — thin or wide — occupies the same horizontal width). Constant-width fonts ensure that, for instance, the 54th character in every line of output from ls -l is always in the same horizontal position on the screen — so columns will always be straight. — JP] To give you an idea of the range of sizes, each alias is written in the font it identifies.

Figure 5-2. Miscellaneous fonts for xterm and other clients

figs/upt3_0502.gif

In these cases, the aliases refer to the dimensions in pixels of each character in the font. (For example, "10x20" is the alias for a font with characters 10 pixels wide by 20 pixels high.) Note, however, that an alias can be virtually any character string.

The default font for many applications, including xterm, is a 6x13 pixel font that has two aliases: "fixed" and "6x13." Many users consider this font to be too small. If you have enough screen space, you might want to use the 10x20 font for xterm windows:

% xterm -fn 10x20 &

You can make this font the default for xterm by specifying it as the value for the font resource variable (Section 6.3):

XTerm*font: 10x20

Another quick way to get a list of fonts that match a given string is to use the xlsfonts program, which accepts a variety of options but may be used as simply as this:

% xlsfonts -fn \*-10-\*

This command will display all of the fonts that are 10 pixels wide. The string \*-10-\* is a wildcard expression matching any font specification containing -10-. Be sure to escape the * and ? characters when specifying a pattern on the command line, to avoid interpolation by the shell.

—VQ and SJC

5.17 The xterm Menus

xterm has four different menus, each providing items that serve different purposes. You display a menu by placing the pointer on the window and simultaneously pressing the CTRL (keyboard) key and a pointer button. When you're using a window manager that provides a titlebar or frame, the pointer must rest within the window proper and not on any window decoration.

Table 5-3 describes the menus and how to display them.

Table 5-3. The xterm menus

Menu title

Display by holding

Use to

Main Options

CTRL, pointer button 1

Enter secure mode; interrupt, stop, etc., the xterm process.

VT Options

CTRL, pointer button 2

Toggle user preferences, including scrollbar, reverse video, margin bell; toggle Tektronix/VT100 mode.

VT Fonts

CTRL, pointer button 3

Select alternative display font.

Tek Options

CTRL, pointer button 2, on Tektronix window

Toggle VT100/Tektronix mode; select display font.

As shown in Table 5-3, three of the four xterm menus are divided into sections separated by horizontal lines. The top portion of each divided menu contains various modes that can be toggled. (The one exception is the Redraw Window item on the Main Options menu, which is a command.) A check mark appears next to a mode that is currently active. Selecting one of these modes toggles its state.

The items on the VT Fonts menu change the font in which text is displayed in the xterm window. Only one of these fonts can be active at a time. To turn one off, you must activate another. See Section 5.18 for information on using the VT Fonts menu.

When you display an xterm menu, the pointer becomes the arrow pointer and initially appears in the menu's title. Once the menu appears, you can release any keyboard key. The menu will remain visible as long as you continue to hold down the appropriate pointer button. (You can move the pointer off the menu without it disappearing.) To toggle a mode or activate a command, drag the pointer down the menu and release the pointer button on the item you want.

If you decide not to select a menu item after the menu has appeared, move the pointer off the menu and release the button. The menu disappears and no action is taken.

You probably won't use the xterm menus too often. You can set most mode entries by using command-line options when invoking xterm or by using entries in a resource file (Section 6.5). See the xterm manpage for a complete list of options and resource variables.

The various modes on the menus are very helpful if you've set (or failed to set) a particular mode on the command line and then decide you want the opposite characteristic. For instance, say you've run xterm without a scrollbar and then decide you want one. You can toggle the scrollbar from the VT Options menu.

The sections below the modes portion of each menu contain various commands. Selecting one of these commands performs the indicated function. Many of these functions can be invoked only from the xterm menus. However, some functions can be invoked in other ways, which are often more convenient. For example, you can remove the xterm window using several of the items on the Main Options menu, but it's probably simpler to type exit or logout, or use a window manager menu or button. Of course, the xterm menus can be very helpful when other methods fail to invoke a function. And some functions (such as Secure Keyboard) are not available in any other way — unless you do a little customizing.

Most people tend to use the mode toggles on the VT Options menu (which allow you to turn features like the scrollbar on and off) and the items on the VT Fonts menu (which allow you to change the display font once the client is running). If you're concerned about security, you may want to invoke secure keyboard mode from the Main Options menu before typing passwords or other sensitive information.

Note that a Release 5 patch (Section 20.9) has eliminated xterm's logging capability for security reasons. If this patch has been applied, your Main Options menu will not offer the Log to File option.

—VQ and SJC

5.18 Changing Fonts Dynamically

Ideally, you want to set up your environment so that xterm windows (and other clients) come up automatically with the characteristics you prefer, including the display font. I use the very large 10x20-pixel font (Section 5.16) for all my xterm windows by specifying the resource variable (Section 6.3):

XTerm*font: 10x20

But if you start an xterm and then decide you want a different font, you do have an option.

5.18.1 VT Fonts Menu

The xterm VT Fonts menu (Section 5.17) allows you to change a window's font on the fly, which is a very handy capability. You can change the font any number of times to accommodate a variety of uses. You might choose to use a large font for text editing; you could then change to a smaller font while a process is running, since you don't need to be reading or typing in that xterm. Since xterm's dimensions are determined by the number of characters wide by the number of lines high, changing the font also changes the size of the window.

When the focus is on an xterm, you display the menu by pressing CTRL and then the third pointer button. The default menu is shown in Figure 5-3.

Figure 5-3. xterm's VT Fonts menu lets you change fonts dynamically

figs/upt3_0503.gif

The items on the VT Fonts menu are toggles, each of which provides a different size display font. If you have not toggled any items on this menu, a check mark will appear next to Default, which is the font specified when the xterm was run. This font could have been specified on the xterm command line or in a resource file. Whatever the case, this font remains the Default for the duration of the current xterm process.

By default, the Unreadable, Tiny, Small, Medium, Large, and Huge menu choices toggle the constant-width fonts shown in Table 5-4.

Table 5-4. VT Fonts menu defaults

Menu item

Default font

Unreadable

nil2

Tiny

5x7

Small

6x10

Medium

7x13

Large

9x15

Huge

10x20

Bring up the VT Fonts menu, and toggle some of these fonts to see what they look like. The first choice is not called Unreadable for nothing, but it does have a practical use.

You can specify your own Unreadable, Tiny, Small, Medium, Large, and Huge fonts using the xterm resource variables font1, font2, font3, font4, font5, and font6. You might want to specify bold alternatives to some of the default fonts. For example, 7x13 bold is somewhat more readable than the standard Medium font.

All of the references to fonts and command-line options also apply to rxvt, which does not, however, support the VT Fonts menu supported by xterm.

5.18.2 Enabling Escape Sequence and Selection

When you first run an xterm window, the final two choices on the VT Fonts menu, Escape Sequence and Selection, are not functional. (They will appear in a lighter typeface than the other selections.) The average user may not care about these items, but if you're experimenting with fonts, they are sometimes useful.

To enable Selection, you first have to select a font name. You can do this simply by highlighting a font name with the pointer, as you would any text selection (Section 5.13). However, it's more likely that you'll use Selection in concert with the xfontsel client. [This is a client that does point-and-click selection of X11 font names; see its manpage. — JP] Once you've selected a font name, you can toggle it using the Selection menu item. A serious limitation: Selection tries to use the last selected text as a font name. If the last selected text was not a valid font name, toggling Selection will get you nothing more than a beep. When there is no primary text selection in memory, the menu item is grayed out again.

The Escape Sequence item is a little more complicated, but once set up it will be available for the duration of the xterm process. To make it available, you first need to change the font by a more primitive method, using a literal escape sequence that you send to the xterm using echo:

val@ruby 181% echo "Esc]50;7x13boldControl-g"

These are the literal keys you type to change the font to 7x13bold. But pressing ESC actually generates the symbol ^[, and CTRL-g appears as ^G, so you'll get a line that looks like this:

val@ruby 181% echo "^[ ]50;7x13bold^G"

If you don't get this string, try typing the CTRL-v character before both the ESC and CTRL-g characters, letting the system know you intend for the following character to be a literal.

I've used a short font name alias (Section 5.16), but you could use a full name or a name with wildcards. Once you've changed the font in this manner, you can toggle it using the Escape Sequence menu item. If you change the font again using the literal escape sequence, that font will be available via the menu item. Note that the trick for changing the font discussed earlier also works in rxvt, but does not enable any font menus.

—VQ and SJC

5.19 Working with xclipboard

The xclipboard client does exactly what you might think: it allows you to save multiple text selections (Section 5.13) and copy them to other windows. Text you copy from an xterm window can be made the CLIPBOARD selection (and thus automatically appear in the xclipboard window). To set this up, you first need to customize xterm using resources.[7]

For text you copy from an xterm to be pasted automatically into xclipboard, the text must be made the CLIPBOARD selection. You set this up to happen by specifying a few translations (Section 6.4) for xterm.[8] Here are the translations I use to coordinate xterm with xclipboard:

*VT100.Translations:    #override\
    Button1 <Btn3Down>: select-end(primary,CUT_BUFFER0,CLIPBOARD)\n\
    !Shift <Btn2Up>:    insert-selection(CLIPBOARD)\n\
    ~Shift ~Ctrl ~Meta <Btn2Up>:  insert-selection(primary,CUT_BUFFER0)

To let you store multiple text selections, the seemingly tiny xclipboard actually provides multiple screens, each of which can be thought of as a separate buffer. Each time you use the pointer to make text the CLIPBOARD selection, the xclipboard advances to a new screen in which it displays and stores the text. If you make a long selection, it might take up more than one screen, but the clipboard still considers it a single buffer. When you make a selection that extends beyond the bounds of the xclipboard window (either horizontally, vertically, or both), scrollbars (Section 5.11) will be activated in the window to allow you to view the entire selection.

To the right of the command buttons is a tiny box that displays a number corresponding to the selection currently in the xclipboard window. Once you have saved multiple selections, you can click on the client's Next and Prev command buttons to move forward and backward among these screens of text.

If you've coordinated xterm with xclipboard using the guidelines outlined earlier, you paste the CLIPBOARD selection in an xterm window by holding down the Shift key and clicking the second pointer button. When you paste the CLIPBOARD selection, you get the selection that's currently being displayed in the xclipboard window. Here's where the client really comes in handy. Suppose you send four selections to xclipboard and you want to paste #2. Just go back to selection #2 using the Prev command button; when you use the pointer command to paste the CLIPBOARD selection, selection #2 is pasted. In Figure 5-4, we've pasted selection #2 into a new file. (Notice that the text is too wide for the xclipboard window and that a horizontal scrollbar has been provided so we can view the entire selection.)

Figure 5-4. Text you copy from an xterm appears in xclipboard

figs/upt3_0504.gif

A selection remains available in xclipboard until you Quit the program or use the Delete button to erase the current buffer.

Use the Save command button to save the text in the current buffer to a file. A dialog will ask you to Accept or Cancel the save to a file with the default name clipboard. You can change the filename using Text widget commands [these are listed in the xedit(1) manpage — JP]. If you want to save multiple selections, you'll need to change the filename each time, or you'll overwrite the previous save.

You can edit text you send to the xclipboard using Text widget commands. When you edit a screenful of text, the xclipboard continues to store the edited version until you delete it or exit the program.

—VQ and SJC

5.20 Problems with Large Selections

If you experiment making large selections with xclipboard, you may discover what seems to be a bug in the program. Though making a new selection usually causes the screen to advance and display the new text, this does not happen reliably after a selection that vertically spans more than one screenful. In these cases, the new selection is saved in the xclipboard (and the number in the small box is incremented to indicate this); however, the xclipboard window does not automatically advance to show you the new current selection. Instead, the previous long selection is still displayed. (For example, though the box says "5," indicating that a fifth selection has been saved, the window is still displaying selection #4.) This is a bit of xclipboard sleight of hand: the new selection has been successfully made, but the appearance of the window belies this fact. The Next button will probably add to your confusion; it will not be available for selection, suggesting that the text in the window is the last selection saved. This is not the case.

To get around this problem and display the actual current selection, press the Previous button. The same long selection (which is, in actuality, the Previous selection) will be displayed again. (The small box will flip back to display the preceding number as well.) Then the Next button will be enabled, and you can click on it to display the actual current selection. The selection displayed in the window and the number in the small box will correspond.[9]

—VQ and SJC

5.21 Tips for Copy and Paste Between Windows

One of my favorite uses for an xterm (which may seem natural to people who've grown up using window systems, but was a pleasant surprise for a guy who started computing with teletypes in 1970) is using a window to accept text pasted from some other window. For instance, in writing this book, I'll have one window open with something happening that I want to put into the book. So I select the text, then paste it into another xterm window — where there's usually a text editor (like vi, with its keymaps for pasting text (Section 18.5)).

You can also use a text editor or Unix utilities to reformat text from one window before pasting it into another. For instance, you'd like to send most of the text in your browser to another window where you're composing an email message. But the web site used those irritating Microsoft Windows-specific quote characters that show up as question marks (?) on any other platform. So you paste the text into an Emacs window, do a quick run of text substitution, and copy the result to paste into the email window.

figs/www.gif Go to http://examples.oreilly.com/upt3 for more information on: requote

Another problem with email messages comes when you're sending a reply to someone who's used very long or jagged lines and the quoted text is a mess. But if you cut the messy text into an xterm window running the requote shell script, you'll get a neatened version. In the following example, the text I paste (cut from a quoted email message) is shown in boldface. Then I press CTRL-d, and the result appears; I can paste it back into the email message:

$ requote
> This is a long line of text that runs on and on and wraps to the next
line without a quote character at the start and it goes on and on and on
and well you know
> This is the next line of text
CTRL-d
> This is a long line of text that runs on and on and wraps to the next
> line without a quote character at the start and it goes on and on and
> on and well you know This is the next line of text

You can pass a fmt width option to tell requote how wide to make the output lines. (Different versions of fmt have different width options: -w, -l, etc.) requote also works great as a vi filter-through (Section 17.18): paste the messy text into vi, and run a command like !{requote to requote the text in place.

requote is a simple script that doesn't try to handle multiple levels of quoting (>> > >>, etc.). The main formatting commands are shown here; the temporary file $temp makes sure fmt has read all the text before the final sed outputs any of it:

${1+"$@"} Section 36.7

sed 's/^> //' |
fmt ${1+"$@"} > $temp
sed 's/^/> /' $temp

Here's another problem like the one requote solves. When I copy text from a browser window, my browser usually puts some whitespace before each line. When I paste the text, it's a mess. I could use a text editor to clean up the lines, but a one-line sed script can do the job faster.

Let's look at three examples of dedent. It removes all space and TAB characters from the start of each line it reads on its standard input, and it writes the result to standard output.

$ dedent > order_confirmation 
    ...paste text into xterm, press CTRL-d...
$ dedent | fmt > johnson 
    ...paste text into xterm, press CTRL-d...
$ dedent | mail -s 'article I mentioned' ali 
    ...paste text into xterm, press CTRL-d...
$

In the first example, I started dedent and pasted text into the xterm. After I pressed CTRL-d, dedent removed leading whitespace from the pasted text and wrote the result to standard output, which the shell had redirected to a file named order_confirmation. In the second example, dedent's output is piped to fmt (Section 21.2) to make the lines neat. (Without dedent, most versions of fmt would indent the reformatted text.) The third example removes leading whitespace, then emails (Section 1.21) the text to ali.

One more thing: many of the tricks discussed earlier may be implemented as shell functions or even emacs functions or vi macro. If you use a mail user agent such as mutt, you can specify your favorite editor for email messages and just call the functions or macros while you edit. This is how I requote my replies to others' email, wrap it to a sane width, and so on. In emacs, ESC q is mapped to the function fill-paragraph, so if I need a paragraph wrapped to a certain width (determined by default-fill-column), I just position the cursor inside the paragraph and call the function. If the fill-prefix variable is properly set (say, to >) it even knows how to wrap several levels of nested quoting in email.

—JP and SJC

5.22 Running a Single Command with xterm -e

The -e option to xterm is useful for running a single command before exiting. For example, if you just want to run a character-based mail program, type the following:

% xterm -e mail

When you quit the mail program, the xterm window exits.

The -e option needs to be the last xterm option on the command line. The remainder of the command line is assumed to be part of the command to be executed by xterm. The new window has the command name in its titlebar by default (unless overridden by other command-line options (Section 5.15)).

One use for xterm -e is for running a window with a login session to a remote system, like this:

% xterm -e ssh  hostname  & 

figs/www.gif Go to http://examples.oreilly.com/upt3 for more information on: ssh-agent

The xterm process runs on the local system, but immediately logs you into the remote machine. You are prompted for a password in the new xterm that pops up — before you can log in to the remote system. This isn't as convenient as putting that command in your X setup file (like .xinitrc or .xsession) — but it's far more secure because you don't need to put your hostname in your .rhosts or .shosts file (Section 1.21), which is a potential security hole. (Or, if you use ssh for your remote login — and you start ssh-agent before you start X — you won't need to type passwords at all during your X session. This is the handiest setup by far.)

You can use -e to create a makeshift X display for any character-based programs you like to run. For example, you might want to keep track of messages sent to the console, but you can't run xterm -C to get console messages because you aren't actually logged in on the console. You might run something like this:

tail -f Section 12.10

% xterm -e tail -f /var/log/messages &

Section 24.21 has more about how this works.

—LM, JP, and SJC

5.23 Don't Quote Arguments to xterm -e

Being a belt-and-suspenders kind of guy, I've gotten in the habit of quoting arguments to commands. This makes good sense with lots of Unix shell commands, but it can get you in trouble with xterm -e. For example, I wanted to set up a job that would open vi in a window to edit a file named .postit. At first, I used the command:

xterm ... -e 'vi .postit' &

only to receive the perplexing message in the resulting window:

Can't execvp vi .postit

The quotes passed the entire string to xterm as an argument, which parsed it as a single command name, rather than a command plus argument. Removing the quotes solved the problem.

—TOR and SJC

[1]  When we refer to terminals throughout this and other chapters, understand that we mean, more often than not, the set of standard terminal-emulation control codes implemented by terminal emulators, such as vt100 or ANSI color. So, though we may refer to a vt100 terminal, we're more likely referring to any terminal-emulator software that can understand and react to that set of control codes.

[2]  getty is spawned by the init at multiuser system startup, and it sets up all ttys, handles the initial login prompt, and then hands successful logins over to login to complete.

[3]  Sure, you don't have to worry about whether there is a local TYMNET dialup nowadays, but back in the day . . .

[4]  Note that there is no user named stucklogin; you're expected to supply the actual login username as an argument to su.

[5]  . . . for some values of "modern", anyway . . . — SJC

[6]  When we refer, throughout the rest of the chapter, to xterm, we're often referring to xterm proper, as well as rxvt and other related terminal programs.

[7]  Since there can be only one CLIPBOARD selection at a time, you can only run one xclipboard per display.

[8]  If you're using a terminal emulator other than xterm, the program should also allow this sort of customization. See the client manpage for the actions (the equivalents of select-end and insert-selection) to include in the translation table.

[9]  By this time, the observant reader will have concluded that xclipboard is a nuisance at best.

CONTENTS