Center String

Center a string within a given width by padding with spaces.

Code

General
printf "%*s%s%*s" $(( (width - ${#s}) / 2 )) "" "$s" $(( (width - ${#s} + 1) / 2 )) ""

Parameters

String to center

Total width

Server

More Bash Snippets