How to change the output color of echo in Linux

后端 未结 29 3996
刺人心
刺人心 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 05:03

    I have just amalgamated the good catches in all solutions and ended up with:

    cecho(){
        RED="\033[0;31m"
        GREEN="\033[0;32m"
        YELLOW="\033[1;33m"
        # ... ADD MORE COLORS
        NC="\033[0m" # No Color
    
        printf "${!1}${2} ${NC}\n"
    }
    

    And you can just call it as:

    cecho "RED" "Helloworld"
    

提交回复
热议问题