O'Reilly logo

Linux and Unix Shell Programming by David Tansley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required