Shell Color and Flicker control
Sometimes custom output is required under the shell, such as adding color to the output, highlighting it, or adding flicker.
Then these color codes or control codes are relatively bad to remember. At this point we can consider the final desired result as a corresponding function,
It's much easier to call functions directly when you're using them.
Format
echo -e "\033[字背景颜色;字体颜色m字符串\033[控制码"
Custom color functions
# # Blue to EchofunctionBlue(){Echo-e"\033[34m[$]\033[0m"}# # Green to EchofunctionGreen(){Echo-e"\033[32m[$]\033[0m"}# # Error to Warning with blinkfunctionBred(){Echo-e"\033[31m\033[01m\033[05m[$]\033[0m"}## Error to warning with blink function byellow () {echo-e "\033[33m\033[01m\033[05m[$]\033[0m"}## Errorfunction bred () { Span class= "Hljs-keyword" >echo-e "\033[31m\033[01m[$]\033[0m"} ## warningfunction byellow () {echo-e "\ 033[33m\033[01m[$]\033[0m "}
You can write these functions into a common shell script, and each time you write another script, call it in the following way.
source /root/bin/common
Or you can paste the above code directly into the currently written script.
Of course, the first way can be recommended. You don't have to copy and paste every time. can be directly source 调用
Example
[Email PROTECTED]/4 $ cat/root/bin/common#!/USR/BIN/ENV Bash## Blue to echo function blue () {ECHO-E "\033[35m[$]\033[0m"}## Green to echo function green () {ECHO-E "\033[32m[$]\033[0m"}## Error to Warning with blinkfunction bred () {ECHO-E] \033[31m\033[01m\ 033[05m[$]\033[0m "}## Error to warning with Blinkfunction Byellow () {ECHO-E "\033[33m\033[01m\033[05m["]\033[0m "}# # errorfunction Red () {echo-e ' \033[31m\033[01m[']\033[0m '}## warningfunction yellow () {ECHO-E "\033[33m\033[ 01m[$]\033[0m "}DEV-WEB-SOLR [/opt/hexo2] 2016-11-28 17:52:03[EMAIL PROTECTED]/4 $ cat/root/bin/test.sh #!/usr/bin/env bashsource/root/bin/commongreen "Hello World with green color" Blue "Hello World with blue color" bred "Error info with Blink" byellow "warning info with Blink"
The test results are as follows
Shell-color-1.png Shell-color-2.png
Additional shell output font background color and font color, control code and other parameters
Font background color
Font Color
Control code
It is commonly used here to set high brightness/underline/blink/close All properties
\33[0m 关闭所有属性 \33[01m 设置高亮度 \33[04m 下划线 \33[05m 闪烁 \33[07m 反显 \33[08m 消隐 \33[30m -- \33[37m 设置前景色 \33[40m -- \33[47m 设置背景色 \33[nA 光标上移n行 \33[nB 光标下移n行 \33[nC 光标右移n行 \33[nD 光标左移n行 \33[y;xH设置光标位置 \33[2J 清屏 \33[K 清除从光标到行尾的内容 \33[s 保存光标位置 \33[u 恢复光标位置 \33[?25l 隐藏光标 \33[?25h 显示光标
Full stack operation and maintenance
Links: https://www.jianshu.com/p/ba1b8aded634
Source: Pinterest
Copyright belongs to the author. Commercial reprint please contact the author for authorization, non-commercial reprint please specify the source.
Shell output color and flicker control