Posted on October 6, 2023 by darshin
How To Use Tput Command In Linux.
The tput command uses the terminfo database to make terminal-dependent information available to the shell. The tput command outputs a string if the attribute CapabilityName is of type string. The output string is an integer if the attribute is of type integer. If the attribute is of type Boolean, the tput command sets the exit value (0 for TRUE, 1 for FALSE), and produces no other output.
Syntax
For Outputting Terminal Information
tput [ -T Type ] [ CapabilityName {clear, init, longname, reset} [ Parameters… ]]
For Using stdin to Process Multiple Capabilities
tput [ -S ]
XTERM DESCRIPTION LIMITATION
The xterm terminal description in the DEC.TI file on AIX® Version 4 provides underline mode by using the SGR attribute. The SMUL and RMUL attributes are not currently defined in the XTERM terminal description on AIX Version 4. Use the more generic capability named SGR.
tput sgr x y
Where x is either a 1 or a 0 to turn standout mode on or off respectively, and y is either a 1 or a 0 to turn underline mode on or off respectively. See the article “terminfo file format” for more details on the SGR capability.
tput sgr 0 1 turn off standout; turn on underline tput sgr 0 0 turn off standout; turn off underline tput sgr 1 1 turn on standout; turn on underline tput sgr 1 0 turn on standout; turn off underline
Flags
In addition to the capability names, the following strings are supported as arguments to the tput subroutine.
Item | Description |
---|---|
clear | Displays the clear screen sequence (this is also a capability name). |
init | Displays the sequence that initializes the user’s terminal in an implementation-dependent manner. |
reset | Displays the sequence that will reset the user’s terminal in an implementation-dependent manner. |
longname | Displays the long name and the specified terminal (or current terminal if none specified). |
-S | Uses stdin. This allow the tput to process multiple capabilities. When using the -S option, the capabilities cannot be entered on the command line. Enter ^D token finished. |
-TType | Indicates the type of terminal. If -T is not specified, the TERM environment variable is used for the terminal. |
Exit Status
This command returns the following exit values:
Item | Description |
---|---|
0 | The requested string was written successfully. |
1 | Unspecified. |
2 | Usage error. |
3 | No information is available about the specified terminal type. |
4 | The specified operand is invalid. |
>4 | An error occurred. |
Examples
- To clear the screen for the current terminal, enter:
tput clear
- To display the number of columns for the current terminals, enter:
tput cols
- To display the number of columns for the aixterm terminal, enter:
tput -Taixterm cols
- To set the shell variable bold to the begin standout mode sequence and the shell variable offbold to the end standout mode sequence, enter:
bold=`tput smso` offbold='tput rmso'
Entering these commands might be followed by the following prompt:
echo "${bold}Name: ${offbold} \c"
- To set the exit value to indicate if the current terminal is a hardcopy terminal, enter:
tput hc
- To initialize the current terminal, enter:
tput init
Files
Item | Description |
---|---|
/usr/share/lib/terminfo/?/* | Contains the terminal descriptor files. |
/usr/include/term.h | Contains the definition files. |
Leave A Comment
What’s happening in your mind about this post !