Shell:终端处理工具tput和stty

获取终端的行列信息:

tput lines #24
tput cols  #80

不显示输入的内容:

#!/bin/bash
echo -n password:
stty -echo  #禁止将输出发送到终端
read password
stty echo   #允许将输出发送到终端
echo #输出一个换行
echo "The password is:${password}"

显示每秒计数的一个例子:

#!/bin/bash
echo -n Count:
count=0
tput sc  #保存光标所在位置
echo -n 0
while true; do
    if [ $count -lt 10 ]; then
        sleep 1
        let count++
        tput rc  #将光标恢复到保存的位置
        tput ed  #清除光标位置到行尾之间的所有内容
        echo -n $count;
    else
        echo
        exit 0;
    fi
done
posted @ 2018-12-20 08:59  xuejianbest  阅读(486)  评论(0编辑  收藏  举报