21.2. Using tput

Now we have gone over the most common names of tput that you will probably use, let’s see how we can use tput in scripts.

21.2.1. Assigning tput commands

We can use the output of all tput names and store them inside more meaningful variable names. The format to do this is:

variable_name= `tput name` 

21.2.2. Using Boolean output

To use the Boolean tput output use the if statement:

STATUS_LINE=‘tput hs‘ 
if $STATUS_LINE; then 
  echo "your terminal has a status line" 
else 
  echo "your terminal has NO status line" 
fi

21.2.3. Using tput in your scripts

Here’s a script that has assigned the tput bel and cl to more meaningful variable names.

							$ pg tput1 
#!/bin/sh 
BELL=`tput bel` 
CLEAR=`tput cl` 

echo $BELL 
echo $CLEAR 

The following ...

Get Linux and Unix Shell Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.