Sometimes we might want to print some text in Bash and we might want it to be centered to the centre of the terminal. It is a cheap way how we can increase clarity of output of our script and make it look much more attractive.
The whole magic is hidden in a program called tput
.
To get number of rows and cols of current terminal, we need just two simple shell substitutions:
TERM_ROWS="$(tput rows)"