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.
23 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"; doneAnd different styles:
for i in {1..7}; do echo -e "\033[$i;31""m different style\033[0m"; doneNotice:
The "\033[0m" at the end of the string is like a closing tag, so that it won't affect the text after.
2Your 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=1Then 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
1I 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