The tput
command produces different kinds of output for each of
the three types of terminal capabilities: string, numeric, and Boolean.
If the terminfo capability given on the command line is a string
capability, tput
displays its value and exits with a status of 0.
If the capability is not defined for the terminal type being used,
tput
produces no output and exits with a status of 1.
If the capability is a numeric capability, tput
displays its
value (an integer). If the capability is not defined for the terminal
type being used, tput
displays the value `-1'. The exit
status is always 0 for numeric capabilities, unless an error occurs
(see section Error Messages for a complete list of the possible exit status
values).
If the capability is a Boolean capability, tput
produces no
output and exits with status 0 if the capability is defined for the
terminal type being used, or status 1 if the capability is not defined.
See section `Definitions of the Terminal Capabilities' in Termcap,
for a more detailed description of termcap capabilities.
The values of numeric capabilities should be saved into shell
variables so they can be used later without having to run tput
again. Here is how it can be done:
For the Bourne, Bourne-again, and Korn shells: To set an environment variable: COLUMNS=`tput cols` export COLUMNS To set a local variable: tabwidth=`tput it` For the C shell: To set an environment variable: setenv COLUMNS `tput cols` To set a local variable: set tabwidth = `tput it`
The values of string capabilities can be saved in shell variables in the
same way, then displayed later using the echo
command. Since
echo
is built into most shells, it runs more quickly than
tput
does. However, using echo
instead of tput
to
display string values can cause problems for capabilities that use
padding, because null padding characters cannot be passed as arguments
to commands, including echo
.
Go to the first, previous, next, last section, table of contents.