LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-08-2013, 09:03 AM   #1
abefroman
Senior Member
 
Registered: Feb 2004
Location: Chicago
Distribution: CentOS
Posts: 1,257

Rep: Reputation: 53
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
 
Old 10-08-2013, 09:19 AM   #2
Habitual
Senior Member
 
Registered: Jan 2011
Distribution: Undecided
Posts: 3,333
Blog Entries: 5

Rep: Reputation: 785Reputation: 785Reputation: 785Reputation: 785Reputation: 785Reputation: 785Reputation: 785
Code:
printf "\033[2;32mHello World\033[0m"
Stolen from here...

Last edited by Habitual; 10-08-2013 at 09:20 AM.
 
1 members found this post helpful.
Old 10-08-2013, 10:03 AM   #3
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,516

Rep: Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896Reputation: 1896
Also works with echo
 
1 members found this post helpful.
Old 10-08-2013, 02:06 PM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,774

Rep: Reputation: 495Reputation: 495Reputation: 495Reputation: 495Reputation: 495
Recent emulators support 256 colours. Deatails: https://en.wikipedia.org/wiki/ANSI_escape_code#Colors
 
Old 10-30-2013, 02:17 PM   #5
abefroman
Senior Member
 
Registered: Feb 2004
Location: Chicago
Distribution: CentOS
Posts: 1,257

Original Poster
Rep: Reputation: 53
Quote:
Originally Posted by grail View Post
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
 
Old 10-30-2013, 04:23 PM   #6
abefroman
Senior Member
 
Registered: Feb 2004
Location: Chicago
Distribution: CentOS
Posts: 1,257

Original Poster
Rep: Reputation: 53
Quote:
Originally Posted by abefroman View Post
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script to find a string and print x lines before and y lines after the string igorza Linux - Newbie 6 04-18-2013 04:31 PM
How to print a message from kernel module to terminal console or tty console yogesh_bansal Linux - Newbie 2 02-27-2009 09:10 AM
Sed command to print matching lines and 2 lines above.. DX398 Programming 12 10-01-2008 08:25 AM
my linux console don't print color in c file ngan_yine Programming 6 10-18-2004 03:31 AM
I cant print in color Fiery Mandriva 0 04-10-2004 09:40 PM


All times are GMT -5. The time now is 03:15 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration