Sommaire |
la commande tput cols renvoi la largeur actuelle du terminal en nombre de caractère, soit le nombre de colonne.
printf -v spaces '%*s' $(tput cols) ''; printf '%s\n' ${spaces// /#}
autre solution:
printf "#%.0s" {$(seq $(tput cols) )}
avec toto variable contenant le titre.
printf -v spaces '%*s' $((($(tput cols)-${#toto}-2)/2)) '' printf '%s' ${spaces// /#};printf " $toto " printf '%s\n' ${spaces// /#}
printtitre () { c=$1 if (( ${#2} % 2 > 0 )) ; then printf "$c"; fi if (( $(tput cols) % 2 > 0 )) ; then printf "$c" ; fi printf "%*s" $(( ($(tput cols) - ${#2} - 2) / 2 )) '' | sed "s/ /$c/g" printf "%s" " $2 " printf "%*s" $(( ($(tput cols) - ${#2} - 2) / 2 )) '' | sed "s/ /$c/g" printf "\n" }