How to change the output color of echo in Linux

后端 未结 29 4053
刺人心
刺人心 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:45

    I've written swag to achieve just that.

    You can just do

    pip install swag
    

    Now you can install all the escape commands as txt files to a given destination via:

    swag install -d 
    

    Or even easier via:

    swag install
    

    Which will install the colors to ~/.colors.

    Either you use them like this:

    echo $(cat ~/.colors/blue.txt) This will be blue
    

    Or this way, which I find actually more interesting:

    swag print -c red -t underline "I will turn red and be underlined"
    

    Check it out on asciinema!

提交回复
热议问题