Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text alignment center - shell script

Tags:

shell

ubuntu

I'm creating a simple console based script using shell script.It will be run on my bash shell Its a simple menu based driven display some set of options.

Now I want to do center align the text depending on the screen size. How do I align the text at center of the screen?Please assis me

like image 425
Karthick V Avatar asked Sep 18 '12 07:09

Karthick V


1 Answers

Finally I found the solution:)

COLUMNS=$(tput cols) 
title="Hello world!" 
printf "%*s\n" $(((${#title}+$COLUMNS)/2)) "$title"
like image 147
Karthick V Avatar answered Oct 04 '22 21:10

Karthick V