Terminals 1295
If we employ the final option, and the character in question is one interpreted spe-
cially by the shell or the terminal driver, then we must precede it with the literal next
character (usually Control-V):
$ stty intr Control-V Control-L
(Although, for readability, a space is shown between the Control-V and the Control-L
in the above example, no white-space characters should be typed between the
Control-V and the desired character.)
It is possible, though unusual, to define terminal special characters to be some-
thing other than control characters:
$ stty intr q Make the interrupt character q
Of course, when we do this, we can no longer use the q key for its usual purpose
(i.e., generating the letter q).
To change terminal flags, such as the TOSTOP flag, we can use commands such as
the following:
$ stty tostop Enable the TOSTOP flag
$ stty -tostop Disable the TOSTOP flag
Sometimes, when developing programs that modify terminal attributes, a program
may crash, leaving the terminal in a state that renders it all but unusable. On a ter-
minal emulator, we have the luxury of simply closing the terminal window and
starting another. Alternatively, we can type in the following character sequence to
restore the terminal flags and special characters to a reasonable state:
Control-J stty sane Control-J
The Control-J character is the real newline character (ASCII 10 decimal). We use
this character because, in some modes, the terminal driver may no longer map the
Enter key (ASCII 13 decimal) into a newline character. We type an initial Control-J
to ensure that we have a fresh command line with no preceding characters. This
may not be easy to verify if, for example, terminal echoing has been disabled.
The stty command operates on the terminal referred to by standard input.
Using the –F option, we can (subject to permission checks) monitor and set the
attributes of a terminal other than the one on which the stty command is run:
$ su Need privilege to access another user’s terminal
Password:
# stty -a -F /dev/tty3 Fetch attributes for terminal /dev/tty3
Output omitted for brevity
The –F option is a Linux-specific extension to the stty command. On many other
UNIX implementations, stty always acts on the terminal referred to by standard input,
and we must use the following alternative form (which can also be used on Linux):
# stty -a < /dev/tty3