6
2
Newbie here. I'm looking for bash script to center and justify text. My script only works with one line of text. How would you improve it?
#!/bin/bash
COLS=$(tput cols)
while true; do
clear
echo -n "Type text "
read text
echo
echo "Menu"
echo "1) Right justify "
echo "2) Center "
echo "3) Exit "
echo
echo -n "Choose [1-3]: "
read opt
echo
case $opt in
1) printf "%*s\n" $COLS "$text"
break
;;
2) printf "%*s\n" $[$COLS/2] "$text"
break
;;
3) break
;;
*)
echo "Error. Press [1-3]"
break
;;
esac
done
3
awk '{ z = '$(tput cols)' - length; y = int(z / 2); x = z - y; printf "%*s%s%*s\n", x, "", $0, y, ""; }'
– galva – 2016-06-08T23:20:34.203