How to change the output color of echo in Linux

Web Technologies Web Development 2 years ago

0 1 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating
_x000D_ _x000D_ 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?

Posted on 16 Aug 2022, this text provides information on Web Development related to Web Technologies. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago
_x000D_ You can use these ANSI escape codes: Black 0;30 Dark Gray 1;30 Red 0;31 Light Red 1;31 Green 0;32 Light Green 1;32 Brown/Orange 0;33 Yellow 1;33 Blue 0;34 Light Blue 1;34 Purple 0;35 Light Purple 1;35 Cyan 0;36 Light Cyan 1;36 Light Gray 0;37 White 1;37 And then use them like this in your script: # .---------- constant part! # vvvv vvvv-- the code from above RED='\033[0;31m' NC='\033[0m' # No Color printf "I ${RED}love${NC} Stack Overflow\n" which prints love in red. From @james-lim's comment, if you are using the echo command, be sure to use the -e flag to allow backslash escapes. # Continued from above example echo -e "I ${RED}love${NC} Stack Overflow" (don't add "\n" when using echo unless you want to add additional empty line)

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

Important Web Technologies Links