格式为:echo -e "\033[背景色;前景色m要输出的字符串\033[0m"
 
参考:
https://wiki.archlinux.org/index.php/Color_Bash_Prompt
http://www.faqs.org/docs/abs/HTML/colorizing.html
http://tldp.org/LDP/abs/html/colorizing.html

颜色编码对照表:


应用实例:修改.bashrc,配置命令提示符为彩色:

# --------------------------------------------------------------------
color_text()
{
    # color_text "Hello Color World." 40 31
    text="$1"
    fore_color="$2"
    background_color="$3"
    echo -e "\033[${background_color};${fore_color}m${text}\033[0m"
}

color_logname()
{
    # pink
    host_name=`hostname`
    color_text "${LOGNAME}@${host_name}:" 40 35
}

color_pwd()
{
    # blue
    color_text "\w\$ " 40 34
}

export PS1="`color_logname``color_pwd`"

本文链接地址: 用echo命令在Shell中输出彩色文字
http://qingfengju.com/index.asp?id=271

分类:Linux 查看次数:6273 发布时间:2011-11-30 14:44:47