网站开发的就业前景如何,网站建设清单表格,数据 导入 wordpress,新网站建设方案1.tput介绍
linux命令tput是可以在终端中进行文本和颜色的控制和格式化#xff0c;其是一个非常有用的命令
2.tput用法
命令#xff1a;
man tput
3.样例
3.1.清除屏幕
命令#xff1a;
tput clear
[rootelasticsearch ~]# tput clear
[rootelasticsearch ~]# 3.2.…1.tput介绍
linux命令tput是可以在终端中进行文本和颜色的控制和格式化其是一个非常有用的命令
2.tput用法
命令
man tput
3.样例
3.1.清除屏幕
命令
tput clear
[rootelasticsearch ~]# tput clear
[rootelasticsearch ~]# 3.2.设置文本样式
加粗
命令
tput bold
[rootelasticsearch ~]# tput bold #加粗
[rootelasticsearch ~]# echo This is bold style.
This is bold style.
[rootelasticsearch ~]# tput sgr0 #恢复默认样式
[rootelasticsearch ~]# 3.3.获取终端的行数和列数
命令
lines$(tput lines)
columns$(tput cols)
echo Terminal has $lines lines and $columns columns.
[rootelasticsearch ~]# lines$(tput lines)
[rootelasticsearch ~]# columns$(tput cols)
[rootelasticsearch ~]# echo Terminal has $lines lines and $columns columns.
Terminal has 10 lines and 113 columns.
[rootelasticsearch ~]# 3.4.移动光标的位置
命令
tput cup 2 20
#将光标移动到第2行20列
[rootelasticsearch ~]# tput cup 2 20[rootelasticsearch ~]# 3.5.隐藏光标
命令
tput civis
[rootelasticsearch ~]# tput civis
[rootelasticsearch ~]#
[rootelasticsearch ~]# 3.6.显示光标
命令
tput cnorm
[rootelasticsearch ~]# tput cnorm
[rootelasticsearch ~]#
[rootelasticsearch ~]# 3.7.设置文本颜色
tput命令可以用来设置文本的前景和背景颜色
3.7.1.将文本字体颜色设置为绿色
命令
tput setaf 2
echo This is green text.
tput sgr0
[rootelasticsearch ~]# tput setaf 2
[rootelasticsearch ~]# echo This is green text.
This is green text.
[rootelasticsearch ~]# tput sgr0
[rootelasticsearch ~]# 3.7.2.将文本背景颜色设置为红色
命令
tput setab 1
echo This text has a red background.
tput sgr0
[rootelasticsearch ~]# tput setab 1
[rootelasticsearch ~]# echo This text has a red background.
This text has a red background.
[rootelasticsearch ~]# tput sgr0
[rootelasticsearch ~]# 通常情况下文本字体颜色及文本背景颜色分配的数值与颜色的对应关系如下可能会因 UNIX 系统的不同而异
数值颜色0黑色1红色2绿色3黄色4蓝色5紫色6深绿色7灰色
3.7.3.文本综合案例
设置文本字体颜色为蓝色文本背景颜色为灰色
脚本
#!/bin/bashblue_font$(tput setaf 4)
grey_background$(tput setab 7)
reset_normal$(tput sgr0)#
echo ${blue_font}${grey_background}I am ztj.${reset_normal}
echo ${blue_font}${grey_background}I work in the Bayshore Consulting Services Co.,Ltd.${reset_normal}
echo ${blue_font}${grey_background}I am from XX,China Mainland .${reset_normal}exit 0[rootelasticsearch ~]# cat tput.sh
#!/bin/bashblue_font$(tput setaf 4)
grey_background$(tput setab 7)
reset_normal$(tput sgr0)#
echo ${blue_font}${grey_background}I am ztj.${reset_normal}
echo ${blue_font}${grey_background}I work in the Bayshore Consulting Services Co.,Ltd.${reset_normal}
echo ${blue_font}${grey_background}I am from XX,China Mainland .${reset_normal}exit 0
[rootelasticsearch ~]# sh tput.sh
I am ztj.
I work in the Bayshore Consulting Services Co.,Ltd.
I am from XX,China Mainland .
[rootelasticsearch ~]#