Printing a Full-Width Line in Bash
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 colsgets 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.
