Bash

Outputting Horizontal Lines in Bash

On the Bash programming language (scripting language) command line on Linux PC/server, this is about how to implement commands to cleanly output horizontal lines and strings.

Shou Arisaka
1 min read
Nov 15, 2025

On the Bash programming language (scripting language) command line on Linux PC/server, this is about how to implement commands to cleanly output horizontal lines and strings.

Image

printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' -

# or 

stty size | perl -ale 'print "-"x$F[1]'

I define it as a function like below so I can specify the delimiter.

horizonal_line(){
  : horizonal_line [delimiter]
  : e.g. horizonal_line "="
  # stty size | perl -ale 'print "-"x$F[1]'
  stty size | perl -ale "print \"${1:-"-"}\"x\$F[1]"
}
$ horizonal_line "*"
***********************************************************************************************
$ horizonal_line "="
===============================================================================================
$ horizonal_line "+"
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
$ horizonal_line "#"
###############################################################################################
$ horizonal_line
-----------------------------------------------------------------------------------------------

Share this article

Shou Arisaka Nov 15, 2025

๐Ÿ”— Copy Links