Color

Black       0;30     Dark Gray     1;30
Red         0;31     Light Red     1;31
Green       0;32     Light Green   1;32
Brown       0;33     Yellow        1;33
Blue        0;34     Light Blue    1;34
Purple      0;35     Light Purple  1;35
Cyan        0;36     Light Cyan    1;36
Light Gray  0;37     White         1;37

Example

test_color.sh

printf '\e[0;30msome text color\e[0m\t'
printf '\e[1;30msome text color\e[0m\n'

printf '\e[0;31msome text color\e[0m\t'
printf '\e[1;31msome text color\e[0m\n'

printf '\e[0;32msome text color\e[0m\t'
printf '\e[1;32msome text color\e[0m\n'

printf '\e[0;33msome text color\e[0m\t'
printf '\e[1;33msome text color\e[0m\n'

printf '\e[0;34msome text color\e[0m\t'
printf '\e[1;34msome text color\e[0m\n'

printf '\e[0;35msome text color\e[0m\t'
printf '\e[1;35msome text color\e[0m\n'

printf '\e[0;36msome text color\e[0m\t'
printf '\e[1;36msome text color\e[0m\n'

printf '\e[0;37msome text color\e[0m\t'
printf '\e[1;37msome text color\e[0m\n'

Output

简单的color function

#!/bin/bash

function color_print
{
    printf '\e[1;31m'
    printf "$1"
    printf '\e[0m'
    printf '\n'
}


color_print 'dasdasdass dasdasdas dasdasdasd dasda\ndaasdas\tdasd\n'

评论

请输入您的评论. 可以使用维基语法: