一. echo命令(-e 参数)
    脚本内容:
    root@ubuntu:/mail$ cat color.sh

    1. #!/bin/bash
    2. echo -e "\033[30m black \033[0m"
    3. echo -e "\033[31m red \033[0m"
    4. echo -e "\033[32m green \033[0m"
    5. echo -e "\033[33m yellow \033[0m"
    6. echo -e "\033[34m blue \033[0m"
    7. echo -e "\033[35m purple \033[0m"
    8. echo -e "\033[36m cyan \033[0m"
    9. echo -e "\033[37m white \033[0m"

    输出结果:
    Shell输出带颜色字体 - 图1
    二. printf命令
    root@ubuntu:/mail$ cat color.sh

    #!/bin/bash
    printf "\033[30m black \033[0m\n"
    printf "\033[31m red \033[0m\n"
    printf "\033[32m green \033[0m\n"
    printf "\033[33m yellow \033[0m\n"
    printf "\033[34m blue \033[0m\n"
    printf "\033[35m purple \033[0m\n"
    printf "\033[36m cyan \033[0m\n"
    printf "\033[37m white \033[0m\n"
    

    输出结果:
    Shell输出带颜色字体 - 图2
    三. 脚本变量方式

    #!/bin/bash
    blackcolor='\E[1;30m'
    redcolor='\E[1;31m'
    greencolor='\E[1;32m'
    yellowcolor='\E[1;33m'
    bluecolor='\E[1;34m'
    purplecolor='\E[1;35m'
    cyancolor='\E[1;36m'
    whitecolor='\E[1;37m'
    echo -e "${blackcolor}black"
    echo -e "${redcolor}red"
    echo -e "${greencolor}green"
    echo -e "${yellowcolor}yellow"
    echo -e "${bluecolor}blue"
    echo -e "${purplecolor}purple"
    echo -e "${cyancolor}cyan"
    echo -e "${whitecolor}white"
    

    输出结果:
    Shell输出带颜色字体 - 图3