SHELL脚本中 tput 的使用技巧 (tput 控制光标位置)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SHELL脚本中 tput 的使用技巧 (tput 控制光标位置)相关的知识,希望对你有一定的参考价值。

知识点:

1)sleep : 用以实现脚本中延时功能,sleep n,延时 n 秒

2)tput : 改变终端显示特性,常见用法如下:

tput lines : 显示终端的行数

tput cols : 显示终端的列数

tput cup line_number collum_number : 定位光标到 line_number 行,collum_number 列的位置

tput setb n : 其中 n 为 0-7 的数字,设置终端的背景颜色

tput setf n : 其中 n 为 0-7 的数字,设置终端的前景色,即字体的颜色

tput sc : 保存光标的位置

tput rc : 恢复光标到上一次保存的位置

tput ed : 清空光标所在位置到屏幕结尾的所有内容

tput smul : 设置下划线

tput rmul : 移除下划线

tput bold : 设置文本样式为粗体


==================华丽的分割线====================

以下脚本用以实现计数器的功能,在终端显示秒数,按秒计数,计数到10 秒

==================================================


#!/bin/bash

# Script name: sleep.sh

# Date: 12/16 2016

# Author: david

# mail: [email protected]

# Version: 1.0

# Description: used for sleep some time when execute the commands


echo -n "Count:" 

tput sc

RETVAL=0

count=0

while true

do

    if [ $count -lt 10 ]

    then

        let count++

        sleep 1

        tput rc

        tput ed

        echo -n $count

    else

        echo

        exit $RETVAL

    fi

done    


本文出自 “davidLee's Linux之路” 博客,请务必保留此出处http://davidlinux.blog.51cto.com/5965954/1883418

以上是关于SHELL脚本中 tput 的使用技巧 (tput 控制光标位置)的主要内容,如果未能解决你的问题,请参考以下文章

Linux命令之修改终端属性tput

shell笔记2 tput

shell tput的用法

为啥 tput 中同时存在 setf/setb 和 setaf/setab?

`tput cols`、`tput lines`和`stty size`之间有啥区别?

tput:在使用 Ruby Net:SSH 时没有指定 $TERM 的值并且没有指定 -T