How to change color when doing echo in tcsh? | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

How to change color when doing echo in tcsh?

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-10-2012
kristinu kristinu is offline
Registered User
 
Join Date: Dec 2009
Last Activity: 14 July 2014, 10:33 PM EDT
Location: London
Posts: 844
Thanks: 59
Thanked 8 Times in 8 Posts
How to change color when doing echo in tcsh?

Is it possible to change the color when doing an echo?

Example, having the following command print in dark blue.


Code:
echo "Hello"

---------- Post updated at 11:50 AM ---------- Previous update was at 10:25 AM ----------

Just figured out how to do it
Sponsored Links
    #2  
Old 01-10-2012
Scott's Avatar
Scott Scott is offline Forum Staff  
Administrator
 
Join Date: Jun 2009
Last Activity: 23 July 2014, 1:32 PM EDT
Location: Zürich
Posts: 8,421
Thanks: 328
Thanked 1,028 Times in 899 Posts
It might help others if you said how...
Sponsored Links
    #3  
Old 01-11-2012
kristinu kristinu is offline
Registered User
 
Join Date: Dec 2009
Last Activity: 14 July 2014, 10:33 PM EDT
Location: London
Posts: 844
Thanks: 59
Thanked 8 Times in 8 Posts
An example is


Code:
echo "\033[1;31m Hello \033[0m"


The '31' and the '1' are the things you change. The '31' is the color code, and the '1' is where you put whatever you want to color. The rest of it is the same for every color coding; the beginning starts coloring, and the stuff afterwards stops coloring ('0' switches it back to default text color). You can use the following color codes:


Code:
30 - black
31 - red
32 - green
33 - yellow
34 - blue
35 - magenta
36 - cyan
37 - white

You can make a pretty nice prompt with it. Also, you can modify it further by including another control char:


Code:
%{\033[1;31m%}%m%{\033[0m%}


In this case, the '1' will make the following color bold. You can use the following modifiers:


Code:
0 - normal
1 - bold
2 - normal again
3 - background color
4 - underline the text
5 - blinking

You can also specify both a foreground and a background color.


Code:
echo "\033[5;41;1;37m   *** ERROR ***   \033[0m"

The Following User Says Thank You to kristinu For This Useful Post:
Scott (01-11-2012)
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Change color on another terminal lhareigh890 Shell Programming and Scripting 2 03-30-2011 11:20 AM
Color on echo output does not work iga3725 Shell Programming and Scripting 4 09-30-2010 11:37 AM
give some color to a word on echo output iga3725 Shell Programming and Scripting 4 07-15-2010 06:01 AM
tcsh/csh: set prompt in production to color red slashdotweenie Shell Programming and Scripting 1 05-14-2010 08:42 AM
ksh - how to echo something in color and bold jakSun8 Shell Programming and Scripting 4 03-19-2008 01:09 PM



All times are GMT -4. The time now is 02:05 PM.