Making shell scripts, sometimes, require some visual presentation. Maybe you need make letters bold, or use a white background. Maybe we want to write in a precise position of the screen. For this worthless activities, I found ‘tput’.
tput is a quite simple command which comes with a basic Solaris installation. I reads termcap database information and let’s you manage it. For now, I know not much about the options and possibilities of this command (man page available), but can show some basic functions:
-Makes text bold:
-Returning to normal text:
-Use a white background:
-Undo white background:
-Knowing rows and cols of a terminal:
tput lines
-Reseting the terminal:
-Initializing the terminal:
-Putting the cursor wherever we want(in the screen):
It gets some options:
-T
-S : is used to tells tput to read several capabilities from the standard input (read the man page for some examples)
Here comes a nonsense example(sorry for the indentation, I’m quite new on this blogs):
#!/bin/bash
# Let's get terminal dimensions
MY_COLS=`tput cols`
MY_ROWS=`tput lines`
# This definitions will be used
# as codes to the terminal.
BOLD=`tput bold`
NORM=`tput sgr0`
# This script will draw a platform going
# from left to right. Crtl+C to stop.
PLATFORM="${BOLD} <====> ${NORM}"
END=0
(( END=MY_COLS-8 ))
clear
while [ 1 ]
do
for (( i=1;i<END;i++ ))
do
tput cup 10 $i
echo $PLATFORM
done
for (( i=END;i!=1;i-- ))
do
tput cup 10 $i
echo $PLATFORM
done
done
I don’t know how many capabilities could be there.
So, if don’t have nice commands like dialog, whiptail and so on, this can help personalizing your scripts.
You have been reading: Another useless post, from Alex Sola
Sphere: Related ContentNo related posts.
Related posts brought to you by Yet Another Related Posts Plugin.

Core Networks homepage
Oracle University