LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   How can I print lines to the console in a certain color? (https://www.linuxquestions.org/questions/programming-9/how-can-i-print-lines-to-the-console-in-a-certain-color-4175480020/)

abefroman 10-08-2013 09:03 AM

How can I print lines to the console in a certain color?
 
How can I print lines to the console in a certain color?

IE. Hello World in a red font, green font, etc.

TIA

Habitual 10-08-2013 09:19 AM

Code:

printf "\033[2;32mHello World\033[0m"
Stolen from here...

grail 10-08-2013 10:03 AM

Also works with echo

NevemTeve 10-08-2013 02:06 PM

Recent emulators support 256 colours. Deatails: https://en.wikipedia.org/wiki/ANSI_escape_code#Colors

abefroman 10-30-2013 02:17 PM

Quote:

Originally Posted by grail (Post 5042150)
Also works with echo

How do you get it to work with echo?

I got the following:
Code:

$ ./color.sh
\033[2;32mHello World\033[0m


abefroman 10-30-2013 04:23 PM

Quote:

Originally Posted by abefroman (Post 5055397)
How do you get it to work with echo?

I got the following:
Code:

$ ./color.sh
\033[2;32mHello World\033[0m


Found it, I have to use echo -e


All times are GMT -5. The time now is 11:50 AM.