How to change the output color of echo in Linux

后端 未结 29 3574
刺人心
刺人心 2020-11-22 04:28

I am trying to print a text in the terminal using echo command.

I want to print the text in a red color. How can I do that?

29条回答
  •  时光说笑
    2020-11-22 04:51

    To expand on this answer, for the lazy of us:

    function echocolor() { # $1 = string
        COLOR='\033[1;33m'
        NC='\033[0m'
        printf "${COLOR}$1${NC}\n"
    }
    
    echo "This won't be colored"
    echocolor "This will be colorful"
    

提交回复
热议问题