How to change the output color of echo in Linux?
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?
Inactive Tutor
answered 05/11/21
echo -e "\033[31mYOUR TEXT\033[0m"
- The -e argument causes echo to interpret the back-slash character in a special way.
- When back-slash interpretation is enabled, "\033" is a representation for the 'escape' character.
- The terminal recognizes many special "escape sequences" that start with the escape character.
- The escape sequence "\033[31m" turns the text color to red.
- The escape sequence "\033[0m" at the end resets the color back to the default.
- A lot more information on these escape sequences can be found at https://en.wikipedia.org/wiki/ANSI_escape_code
Still looking for help? Get the right answer, fast.
OR
Find an Online Tutor Now
Choose an expert and meet online.
No packages or subscriptions, pay only for the time you need.