Skip to content

Instantly share code, notes, and snippets.

View n0ct's full-sized avatar

bZx n0ct

  • Clermont-Ferrand France
View GitHub Profile
@TrinityCoder
TrinityCoder / center_text_in_bash.md
Last active August 8, 2024 17:55
How to center text in Bash

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)"