新手在这里。我正在寻找bash脚本来居中并证明文本的合理性。我的脚本只适用于一行文本。你会如何改进它?
#!/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
awk '{ z = '$(tput cols)' - length; y = int(z / 2); x = z - y; printf "%*s%s%*s\n", x, "", $0, y, ""; }'