How to display colour text in terminal?

I want to display colour text in terminal(bash shell). Tried with this approach:

echo -e "\e[1;31m This is red text \e[0m"

But it doesn't change the text colour to red.

2

3 Answers

You may try with this command:

echo -e "\033[1;31m This is red text"

31 is the "color" and 1 is the "style".

You can play with different color:

for i in {30..37}; do echo -e "\033[1;$i""m colorful text\033[0m"; done

And different styles:

for i in {1..7}; do echo -e "\033[$i;31""m different style\033[0m"; done

Notice:

The "\033[0m" at the end of the string is like a closing tag, so that it won't affect the text after.

2

Your problem is that most probably colored output is disabled in your terminal.

To enable it, edit your .bashrc file and add the following:

export CLICOLOR=1

Then go in your Terminal settings -> Preferences -> Profiles -> Text -> Display ANSI colors.

Open a new terminal and you should be ready to go!

Source: OS X Terminal Colors @ stackoverflow

1

I don’t know if this is what you require but if you go to Terminal -> Preferences... -> Profiles then you can change your text colour to whichever color you want by going to the Text option and Selecting the colour that you want or there are some predefined templates to suit your style.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like