Colorizing text

前端 未结 2 924
别跟我提以往
别跟我提以往 2021-01-01 07:37

How can I show text in color with Bash?

  • a: white text on brown background
  • b: black text on yellow background

相关标签:
2条回答
  • 2021-01-01 08:14
    # text
    black='\e[0;30m'
    white='\e[0;37m'
    yellow='\e[0;33m'
    
    # background
    white_bg='\e[47m'
    
    echo -e "${black}black test"
    echo -e "${white_bg}white bg and black test"
    echo -e "${yellow}yellow test"
    
    0 讨论(0)
  • 2021-01-01 08:16

    You can provide some colors like these in your ~/.bashrc

    txtblk='\e[0;30m' # Black - Regular
    txtred='\e[0;31m' # Red
    txtgrn='\e[0;32m' # Green
    txtylw='\e[0;33m' # Yellow
    txtblu='\e[0;34m' # Blue
    txtpur='\e[0;35m' # Purple
    txtcyn='\e[0;36m' # Cyan
    txtwht='\e[0;37m' # White
    

    Afterwards you can use echo:

    echo -e "${txtred}asd${txtwht}"
    

    Here you can find more colors.

    0 讨论(0)
提交回复
热议问题