1:tput命令:通过
tput命令可以使脚本
创建交互性的、专业性强的屏幕输出
2:在使用tput前,需要在脚本或命令行中使用 tput
命令初始化终端。
tput init
3: tput常用命令
4:例1 控制字符串显示在屏幕*
#!/bin/sh
xy(){_R=$1_C=$2_TEXT=$3echo "\033[40;32m"tput cup $_R $_Cecho $_TEXTecho "\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 $_STRxy $_ROW $_NEW_COL}
tput initcentertxt 4 "MAINWINDOW"
结果:
例2 查看终端属性
#!/bin/sh
tput inittput clear
echo "terminal info:"infocmp -1 $TERM | while read LINEdocase $LINE inbel*) 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" ;;esacdone
结果: