Linux shell script output with color text

Source: Internet
Author: User

The color of the text terminal can be generated by using the ANSI unconventional character sequence. Example:

    1. echo -e "\033[44;37;5m ME \033[0m COOL"

The above command sets the function as follows:

  1. 背景色为蓝色,前景色为白色,字体闪烁,输出字符“ME”,然后重新设置屏幕到缺省设置,输出字符 “COOL”。
  2. “e”是命令 echo 的一个可选项,它用于激活特殊字符的解析器。
  3. “\033”引导非常规字符序列。
  4. “m”意味着设置属性然后结束非常规字符序列,这个例子里真正有效的字符是“44;37;5” 和“0”。
  5. 修改“44;37;5”可以生成不同颜色的组合,数值和编码的前后顺序没有关系。

The encoding you can choose is as follows:

  1.   编码 颜色/动作
  2.   0 重新设置属性到缺省设置
  3.   1 设置粗体
  4.   2 设置一半亮度(模拟彩色显示器的颜色)
  5.   4 设置下划线(模拟彩色显示器的颜色)
  6.   5 设置闪烁
  7.   7 设置反向图象
  8.   22 设置一般密度
  9.   24 关闭下划线
  10.   25 关闭闪烁
  11.   27 关闭反向图象
  12.   30 设置黑色前景
  13.   31 设置红色前景
  14.   32 设置绿色前景
  15.   33 设置棕色前景
  16.   34 设置蓝色前景
  17.   35 设置紫色前景
  18.   36 设置青色前景
  19.   37 设置白色前景
  20.   38 在缺省的前景颜色上设置下划线
  21.   39 在缺省的前景颜色上关闭下划线
  22.   40 设置黑色背景
  23.   41 设置红色背景
  24.   42 设置绿色背景
  25.   43 设置棕色背景
  26.   44 设置蓝色背景
  27.   45 设置紫色背景
  28.   46 设置青色背景
  29.   47 设置白色背景
  30.   49 设置缺省黑色背景
  31.   例如:在编译脚本文件时,对服务启动完成后的OK字符串设置成绿色

Linux shell script output with color text

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.