ksh, font colour


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ksh, font colour
# 1  
Old 12-18-2008
ksh, font colour

hi all,
how do i change the colour of text if i am using printf ?? in my script i am printing out response times from the server and i wanted to print out the max response time in red.


ta.
# 2  
Old 12-18-2008
The "right" way is to output the character sequence needed based on terminal type... thus you get the sequence from termcap/terminfo. Most systems will now use terminfo... you can use tput to output a capability string. You can use infocmp (if installed) to view the current terminfo database for your terminal type.

As far as "red" goes, that could vary. Often times you use the "tput setaf #" command to output a color by NUMBER. Red is often times color 1, so
tput setaf 1 would change the foreground to red. In a script you would capture the string to use in output (at least that's what I'd do). So if "tput setaf 1" means red foreground, and "tput sgr0" means reset graphics/charsets/color to nothing... then:

r=`tput setaf 1`
N=`tput sgr0`

echo "The following ${r}WORD${N} should be in red."

Or

printf "The following %sWORD%s should be in red.\n" $r $N


Because terminal type can vary, even from one terminal client to another, it's difficult to depend on things like color (especially color).
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed colour change

Hi, I am trying to write a script which will email a backup report from the server, The contents of the email will be: ---------------------- ---- -- ---- ----- ---- ------- ---- ------- ------- | | | | |Chnge|Wkng| | | | | | ... (6 Replies)
Discussion started by: Bdoydie
6 Replies

2. Programming

Cshell help with change colour in print

i want to ask how to change the colour of prompt message from use? and also how to change colour in printing........ i want to change it as blue colour and red colour, but i found many website still don't know how to do. how's the command is wrote? thz really!! (1 Reply)
Discussion started by: wendy1089
1 Replies

3. HP-UX

hpux top colour

Hello, is there some way to change b/w colour of top command output in hpux B.11.31 ? (1 Reply)
Discussion started by: tonijel
1 Replies

4. Shell Programming and Scripting

random colour xterm alias

I used to have this but do not know where it went - a script or an alias that: opens a new xterm window with a random background colour. I have this off "the internets" : alias xterm1="xterm ... -bg \#* printf '%02x%02x%02x' {repeat 3 times $((RANDOM%128+128))}` &" this gives me an... (2 Replies)
Discussion started by: arcadia
2 Replies

5. HP-UX

How to change font and colour in mail sent from Unix

Dear All, We have following code to send mails from unix to users. We want to see few sentences of mail in bold font or to hightlight few lines in different colours. Could you please let me know how can we do it in function construct_body. ... (3 Replies)
Discussion started by: yogichavan
3 Replies

6. Shell Programming and Scripting

#!/bin/sh script is in white colour

Hello friends. I realize that my question is naive, but I really want to know, why one of my scripts is in white colour (I mean letters in the body are white) while 3 residuary are multicoloured. I'm asking because I have a little problem with this particular script. It's absolutely the same as... (1 Reply)
Discussion started by: MarGur
1 Replies

7. Shell Programming and Scripting

How to change the font colour in unix ?

Could you pls tell me how to change the font colour in unix ? What is the syntax ? (3 Replies)
Discussion started by: sars
3 Replies

8. Shell Programming and Scripting

VT100 terminal and colour

Good day all I am looking for a way to change colours in a text file that get tailed. I have tried using tput, however this does not seem to work. terminal type is using putty and vt100 emulation. Any ideas. :rolleyes: Thanks J (6 Replies)
Discussion started by: jhansrod
6 Replies
Login or Register to Ask a Question