How to use tput command in Linux.

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.

ItemDescription
clearDisplays the clear screen sequence (this is also a capability name).
initDisplays the sequence that initializes the user’s terminal in an implementation-dependent manner.
resetDisplays the sequence that will reset the user’s terminal in an implementation-dependent manner.
longnameDisplays the long name and the specified terminal (or current terminal if none specified).
-SUses 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.
-TTypeIndicates 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:

ItemDescription
0The requested string was written successfully.
1Unspecified.
2Usage error.
3No information is available about the specified terminal type.
4The specified operand is invalid.
>4An error occurred.

 

Examples

  1. To clear the screen for the current terminal, enter:
    tput clear
  2. To display the number of columns for the current terminals, enter:
    tput cols
  3. To display the number of columns for the aixterm terminal, enter:

    tput  -Taixterm cols

  4. 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"
  5. To set the exit value to indicate if the current terminal is a hardcopy terminal, enter:
    tput hc
  6. To initialize the current terminal, enter:
    tput init

 

Files

ItemDescription
/usr/share/lib/terminfo/?/*Contains the terminal descriptor files.
/usr/include/term.hContains the definition files.

Leave A Comment

What’s happening in your mind about this post !

Your email address will not be published. Required fields are marked *