1846321 Members
3456 Online
110256 Solutions
New Discussion

Shell colour

 
baiju_3
Esteemed Contributor

Shell colour

Hi ,

I like to do some fancy stuff. Is there any way to give colours to echo messages from shell scripts .

Are there any tput or any escape sequences available .

I have seen some one did the same in SCO Unix . Is it possible in HP ?


Thanks in Advance.

Good things Just Got better (Plz,not stolen from advertisement -:) )
8 REPLIES 8
Rick Garland
Honored Contributor

Re: Shell colour

You're right. In SCO I did this all the time.
Do not see the same in HPUX though.
Gopi Sekar
Honored Contributor

Re: Shell colour


i dont whether it will work in HP, but it works for me in linux console

echo -en "\E[$c1;$c2m" followed by the text

where $c1 and $c2 are numeric values which sets color.

to reset you can do 'tput sgr0'

Hope this helps,
Gopi
Never Never Never Giveup
Mel Burslan
Honored Contributor

Re: Shell colour

Handling of color escape characters are a function of the shell you are using. I have never tried it but I am almost certain, if you use the same bash as your hpux shell, and a teminal emulator capable of handling color codes, you will get the fancy colored stuff like almost any linux flaovir in default configuration.
________________________________
UNIX because I majored in cryptology...
Alzhy
Honored Contributor

Re: Shell colour

Whatever ANSI escape sequences for COLOURS, HIGHLIGHTS, BOLD, UNDERLINE - should still work on HP-UX.

The way these codes is interpreted is a function of your shell and the Terminal characteristics. Most notably -- if you're using VT52, VT100, VT102 and some color_xterm variations.

Hakuna Matata.
Bill Hassell
Honored Contributor

Re: Shell colour

Actually, color is always a function of the terminal, not the shell. While you can change commands with an alias or change $PS1 to contain a special eascape sequence that produces colors, it is the terminal the displays the results. So you start with your emulator (I assume you aren't using a 'real' glass terminal which would likely not have any colors). If it is a vt100, forget color--there are no colors on a vt100. Now there are some programs that lie and say they are a vt100 but implement things like multiple pages of memory or variable line widths, none of which are vt100 feature (for the real story: http://vt100.net/ ).

So you start by reading about your terminal emulator. It's important to understand the differences between a PC running an Xwindow emulator versus running a terminal emulator (like Hyperterminal). Xwindows does not have any terminal emulator. Instead, you login to a remote system and 'steal' a copy of xterm or dtterm or hpterm and redisplay the results back to your screen. Your emulator is the program you are running and has little to do with the PC.

Color is usually defined (in a compatible manner) with the terminfo database and the Curses library. The primary tool is tput (to display or set features) and untic will show you what a particular terminal knows how to do. After you look at man terminfo, you'll realize that there is a *lot* to fancy terminal features.

Now some emulators (like WRQ's Reflection) will implement a color map to add additional cues for what are monochrome enhancements like blink and underline, etc. You can use this short script to display the most common enhancements:

HB=$(tput dim) # dim text
HV=$(tput smso) # 1/2 bright inverse
IV=$(tput bold) # inverse
UL=$(tput smul) # underline
BL=$(tput blink) # blink
EE=$(tput sgr0) # end enhancements

echo
echo "Typical names:"
echo "\t$EE Normal $IV Inverse $EE$HB Dim $EE$BL Blink $EE$HV halfbrite $EE$UL underline $EE"

echo
echo "Curses capname (tput)"
echo "\t$EE SGR0 $IV BOLD $EE$HB DIM $EE$BL BLINK $EE$HV SMSO $EE$UL SMUL $EE"
echo


Bill Hassell, sysadmin
Florian Heigl (new acc)
Honored Contributor

Re: Shell colour

I only know that hpterm and dtterm can handle colours, curses and all the fancy things, the default xterm to my knowledge can't display colours.
yesterday I stood at the edge. Today I'm one step ahead.
Cem Tugrul
Esteemed Contributor

Re: Shell colour

i am using my root profile's of my systems
like;
PS1="`tput bold`$(hostname):`tput rmso`\$PWD\#"

it makes my hostnames bold when i connect
via telnet

Good Luck,
Our greatest duty in this life is to help others. And please, if you can't
Dino_4
Frequent Advisor

Re: Shell colour


U can try 'tput setaf #'

where # is a number

0 - black
1 - red
2 - green

and so on.

As written, it all depends on your settings, but it works for me on my HPUX-Box