shell腳本學習(一)

1:tput命令:通過tput命令可以使腳本創建交互性的、專業性強的屏幕輸出
 

2:在使用tput前,需要在腳本或命令行中使用 tput命令初始化終端。
tput init
 
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

 
 結果:

發佈了32 篇原創文章 · 獲贊 6 · 訪問量 12萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章