Operating System - HP-UX
1753868 Members
7229 Online
108809 Solutions
New Discussion

Adding color to shell output results

 
Mark Watson_2
Occasional Contributor

Adding color to shell output results

In other OS's (Linux and Sun) i can write a shell - listed below - and the results will display back in color. i am not able to get this to work in HPUX. Am i missing something??

 

# Global options
COLORALL0="\033[0;1;30m### COLORALL0 ### \033[0;0m"
COLORALL1="\033[0;1;31m### COLORALL1 ### \033[0;0m"
COLORALL2="\033[0;1;32m### COLORALL2 ### \033[0;0m"
COLORALL3="\033[0;1;33m### COLORALL3 ### \033[0;0m"
COLORALL4="\033[0;1;34m### COLORALL4 ### \033[0;0m"
COLORALL5="\033[0;1;35m### COLORALL5 ### \033[0;0m"
COLORALL6="\033[0;1;36m### COLORALL6 ### \033[0;0m"
COLORALL7="\033[0;1;37m### COLORALL7 ### \033[0;0m"
COLORALL8="\033[0;1;38m### COLORALL8 ### \033[0;0m"
COLORALL9="\033[0;1;39m### COLORALL9 ### \033[0;0m"

NUM=9
until [[ $NUM = 0 ]]
do
   eval echo "\$COLORALL$NUM"
   NUM=`expr ${NUM} - 1`
done

2 REPLIES 2
James R. Ferguson
Acclaimed Contributor

Re: Adding color to shell output results

Hi:

 

First, your terminal type must support color.  Then, it is safest to use 'tput'.  Have a look at the 'tput()' manpages.

 

See Bill Hassell's post, here, for more insight:

 

http://h30499.www3.hp.com/t5/General/Colors-within-terminal-app-on-HP-UX-11i/m-p/3131098/highlight/true#M83156

 

Regards!

 

...JRF...

Bill Hassell
Honored Contributor

Re: Adding color to shell output results

To expand a bit on colors, James is correct -- the shell knows nothing about colors. And historically, real terminals (tm) have only two colors (black and white, possibly black and green or orange). Colors are typically associated with graphics and in the word of Unixes, the PC or Xwindow device brought the possibility of colors for text.  As mentioned in the link above, there are some 1800 terminal manufacturer and models that have an entry in the terminfo (man terminfo) database on HP-UX. But it's a Tower of Babel -- Wyse is incompatible with Tektronix which is incompatible with Dec which is incompatible with HP, etc. So you first establish what kind of terminal you have. PuTTY is an emulator (imitator) of the classic DEC VT100, but a vt100 has no color except black and white. Yet PuTTY allows you to change the font and background color and (not keeping with a proper emulator) adds ANSI color escape codes. Then there are PC products like SecureCRT, Reflection/Attachmate, Minisoft, QCTerm, etc which have other emulation capabilities. To make things really fun, Linux is typically run in Xwindows so the emulator can be xterm. But when the Linux box telnets into the HP-UX system, the TERM value preset from Linux is "linux" which is not a terminal at all.

 

So there is no standard -- or better yet, there so many to choose from that there is no single answer. When the emulator and display hardware are constrained, then there can be a solution but you'll need to see what is required for your emulator, then provide appropriate aliases. Note that you may have to consider other users accessing the system which do not share the same hardware and emulator. That's why the command: ttytype(1) is so useful in .profile



Bill Hassell, sysadmin