Linux基础命令 | 您所在的位置:网站首页 › 彩色脚本 › Linux基础命令 |
描述
在ANSI/VT100 终端和终端仿真器不只是能够显示黑色和白色文本;由于转义序列,它们可以显示颜色和格式化的文本。 这些序列由转义字符 (通常由^[或表示)后接其他一些字符:FormatCode组成。[FormatCodem 在 Bash, 字符可以使用以下语法获取字符: \e\033\x1B实例: 代码(Bash)预览echo -e “ \ e [31mHello World \ e [0m”echo -e “ \ 033 [31mHello \ e [0m World” 注意: 该命令的-e选项echo启用对转义序列的解析。\e[0m序列删除所有属性(格式和颜色)。在每个彩色文本的末尾都最好添加它。 说明: \e 转义起始符,定义一个转义序列, 可以使用 \033或者\x1B代替[ 表示开始定义颜色m 转义终止符,表示颜色定义完毕再次使用 \e[ ,表示再次开启颜色定义,0表示使用默认的颜色,m表示颜色定义结束,所以 \e[0m 的作用是恢复之前的配色方案 格式化(Formatting) 描述: 这是最常用的用于格式化文本的控制序列。它们的支持取决于所使用的终端(请参阅兼容性列表)。 集合(SET) 编码描述实例预览1粗体/明亮(Bold/Bright)echo -e "Normal \e[1mBold"2暗淡(Dim)echo -e "Normal \e[2mDim"4下划线(Underlined)echo -e "Normal \e[4mUnderlined""5闪烁(Blink)1echo -e "Normal \e[5mBlink"不闪烁7反转(反转前景色和背景色)echo -e "Normal \e[7minverted"8隐藏(对密码有用)echo -e "Normal \e[8mHidden" 重置(Reset) 编码描述实例预览0重置所有属性echo -e "\e[0mNormal Text"21重设粗体/明亮echo -e "Normal \e[1mBold \e[21mNormal"22重设暗淡echo -e "Normal \e[2mDim \e[22mNormal"24重设下划线echo -e "Normal \e[4mUnderlined \e[24mNormal"25重设闪烁echo -e "Normal \e[5mBlink \e[25mNormal"这里不能显示动图27重设反转echo -e "Normal \e[7minverted \e[27mNormal"28重设隐藏echo -e "Normal \e[8mHidden \e[28mNormal" 8/16 色 前景色(文字) 编码描述实例预览39默认前景色echo -e "Default \e[39mDefault"30黑色echo -e "Default \e[30mBlack"31红色echo -e "Default \e[31mRed"32绿色echo -e "Default \e[32mGreen"33黄色echo -e "Default \e[33mYellow"34蓝色echo -e "Default \e[34mBlue"35品红echo -e "Default \e[35mMagenta"36青色echo -e "Default \e[36mCyan"37浅灰echo -e "Default \e[37mLight gray"90深灰色echo -e "Default \e[90mDark gray"91淡红色echo -e "Default \e[91mLight red"92浅绿色echo -e "Default \e[92mLight green"93浅黄色echo -e "Default \e[93mLight yellow"94淡蓝色echo -e "Default \e[94mLight blue"95淡品红echo -e "Default \e[95mLight magenta"96浅青绿echo -e "Default \e[96mLight cyan"97白色echo -e "Default \e[97mWhite" 背景(Background) 编码描述实例预览49默认背景色echo -e "Default \e[49mDefault"40黑色echo -e "Default \e[40mBlack"41红色echo -e "Default \e[41mRed"42绿色echo -e "Default \e[42mGreen"43黄色echo -e "Default \e[43mYellow"44蓝色echo -e "Default \e[44mBlue"45品红echo -e "Default \e[45mMagenta"46青色echo -e "Default \e[46mCyan"47浅灰echo -e "Default \e[47mLight gray"100深灰色echo -e "Default \e[100mDark gray"101浅红色echo -e "Default \e[101mLight red"102浅绿色echo -e "Default \e[102mLight green"103浅黄色echo -e "Default \e[103mLight yellow"104浅蓝echo -e "Default \e[104mLight blue"105浅洋红色echo -e "Default \e[105mLight magenta"106浅青色echo -e "Default \e[106mLight cyan"107白色echo -e "Default \e[107mWhite" 88/256色 说明: 某些终端(请参阅兼容性列表)可以支持88或256种颜色。这是允许您使用它们的控制序列。颜色数字256仅受vte支持(GNOME终端,XFCE4终端,Nautilus终端,终结器等)88色终端(如rxvt)与256色终端的色图不同。要显示88色终端的颜色图,请在88色终端中运行256-colors.sh脚本。 前景色(文字)要使用前景上的256种颜色(文本颜色)中的一种,控制顺序为[38;5;ColorNumberm,其中ColorNumber是以下颜色之一: 实例: 代码预览echo -e “ \ e [38; 5; 82mHello \ e [38; 5; 198mWorld”for i in {16..21} {21..16} ; do echo -en "\e[38;5;${i}m#\e[0m" ; done ; echo 背景色要在背景上使用256种颜色之一,控制顺序为[48;5;ColorNumberm,其中ColorNumber是以下颜色之一: 实例: 代码预览echo -e "\e[40;38;5;82m Hello \e[30;48;5;82m World \e[0m"for i in {16..21} {21..16} ; do echo -en "\e[48;5;${i}m \e[0m" ; done ; echo 属性组合终端允许属性组合。属性必须用分号(“ ;”)分隔。 实例: 描述代码预览加粗加下划线echo -e "\e[1;4mBold and Underlined"粗体+红色前景+绿色背景echo -e "\e[1;31;42m Yes it is awful \e[0m" demo程序(Demonstration programs) 颜色和格式(16种颜色)以下Shell脚本显示了许多可能的属性组合(但不是全部,因为它一次只使用一个格式属性)。 点击下载: colors_and_formatting.sh #!/bin/bash # This program is free software. It comes without any warranty, to # the extent permitted by applicable law. You can redistribute it # and/or modify it under the terms of the Do What The Fuck You Want # To Public License, Version 2, as published by Sam Hocevar. See # http://sam.zoy.org/wtfpl/COPYING for more details. #Background for clbg in {40..47} {100..107} 49 ; do #Foreground for clfg in {30..37} {90..97} 39 ; do #Formatting for attr in 0 1 2 4 5 7 ; do #Print the result echo -en "\e[${attr};${clbg};${clfg}m ^[${attr};${clbg};${clfg}m \e[0m" done echo #Newline done done exit 0 256 色以下脚本显示了某些终端和终端仿真器(例如XTerm和GNOME Terminal)上可用的256种颜色。 点击下载:256-colors.sh #!/bin/bash # This program is free software. It comes without any warranty, to # the extent permitted by applicable law. You can redistribute it # and/or modify it under the terms of the Do What The Fuck You Want # To Public License, Version 2, as published by Sam Hocevar. See # http://sam.zoy.org/wtfpl/COPYING for more details. for fgbg in 38 48 ; do # Foreground / Background for color in {0..255} ; do # Colors # Display the color printf "\e[${fgbg};5;%sm %3s \e[0m" $color $color # Display 6 colors per lines if [ $((($color + 1) % 6)) == 4 ] ; then echo # New line fi done echo # New line done exit 0不适用于大多数的终端仿真器,可在tty和Term中使用 ↩︎ |
CopyRight 2018-2019 实验室设备网 版权所有 |