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

 
 结果:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值