Skip to main content

Command Palette

Search for a command to run...

Printing a Full-Width Line in Bash

Updated
1 min readView as Markdown

Sometimes in the terminal you want a visual separator, like a line that stretches across the entire width of your screen. It makes logs, scripts, and output much easier to read.

You can generate a line that automatically matches your terminal width using this little Bash snippet.

First, create the line:

line=$(yes ─ | head -n$(tput cols) | tr -d '\n')

How it works:

  • tput cols gets the current width of your terminal in characters.

  • yes ─ repeats the character endlessly.

  • head -n$(tput cols) limits it to exactly the number of characters your terminal can fit.

  • tr -d '\n' removes the newlines, leaving a continuous line.

Next, print it in bold green (or change the color to whatever you like):

printf "\e[1m\e[92m$line\x1b[39;49;00m\n"

That prints a clean line across the screen the exact width of the terminal.


Why This Is Useful

  • Use it as a separator in shell scripts.

  • Highlight sections in logs.

  • Add visual flair to status outputs or menus.

And since it uses tput cols, it will adapt to whatever size your terminal is.

More from this blog

RH Scripts

16 posts