1:tput命令:通过
tput命令可以使脚本
创建交互性的、专业性强的屏幕输出
2:在使用tput前,需要在脚本或命令行中使用 tput 命令初始化终端。
2:在使用tput前,需要在脚本或命令行中使用 tput 命令初始化终端。
tput init
3: tput常用命令
4:例1 控制字符串显示在屏幕中央
结果:
例2 查看终端属性
结果:

3: tput常用命令
4:例1 控制字符串显示在屏幕中央
#!/bin/sh
xy()
{
_R=$1
_C=$2
_TEXT=$3
echo "\033[40;32m"
tput cup $_R $_C
echo $_TEXT
echo "\033[0m"
}
centertxt()
{
_ROW=$1
_STR=$2
LEN=`echo $_STR |wc -c`
COLS=`tput cols`
_NEW_COL=`expr \( $COLS - $LEN \) / 2`
_NEW_ROW=`expr $_ROW / 2`
xy $_NEW_ROW $_NEW_COL $_STR
xy $_ROW $_NEW_COL
}
tput init
centertxt 4 "MAINWINDOW"
结果:
例2 查看终端属性
#!/bin/sh
tput init
tput clear
echo "terminal info:"
infocmp -1 $TERM | while read LINE
do
case $LINE in
bel*) echo "$LINE:sound the bell" ;;
blink*) echo "$LINE:begin blinking mode" ;;
bold*) echo "$LINE:make it bold" ;;
el*) echo "$LINE:clear to end of line" ;;
civis*) echo "$LINE:turn sursor off" ;;
cnorm*) echo "$LINE:turn sursor on" ;;
clear*) echo "$LINE:clear the screen" ;;
kcuul*) echo "$LINE:up arrow" ;;
kcubl*) echo "$LINE:left arrow" ;;
kcufl*) echo "$LINE:right arrow" ;;
kcudl*) echo "$LINE:down arrow" ;;
esac
done结果: