Operating System - HP-UX
1832695 Members
2936 Online
110043 Solutions
New Discussion

Text formatting is script

 
Khashru
Valued Contributor

Text formatting is script

Hi I am writin g script is posix shell. i want to bold and colar a specific word or line how can I do that.
8 REPLIES 8
A. Clay Stephenson
Acclaimed Contributor

Re: Text formatting is script

Bolding, underlining, color is purely a function of the output device. The idea is that you query the terminfo datadase for these sequences.

Here is an example:

BOLDDARKGRAY=$(tput bold; tput setaf 0)
LIGHTGRAY=$(tput setaf 7)

echo "${BOLDDARKGRAY}Mickey Mouse"
echo "${LIGHTGRAY}Donald Duck"

Generally the "smso" and "rmso" (start standout mode and remove standout mode) are the two sequences that you can count on a terminal having. The setaf sequences may or may not be available; it depends upon the terminfo entry. The good news is that if a sequence is undefined a null string is returned so you can still output it safely if the feature is unsupported. You can also use terminfo sequences to clear the screeen and position the cursor.


Man tput and terminfo for details.
If it ain't broke, I can fix that.
Khashru
Valued Contributor

Re: Text formatting is script

I want to see it in the login shell.
A. Clay Stephenson
Acclaimed Contributor

Re: Text formatting is script

What is a login shell? I know what a POSIX, Korn, Bourne, Bash, and C shell is but I don't know what a login shell is? If you mean you want to see "Login: " and "Password: " in bold then that's rather difficult and rather dangerous because at that point, you don't know what TERM is and the last thing you want to do is send escape sequences to a terminal before you know if those sequences are going to send that terminal into some unknown mode although the most likely result is that garbage will be output. UNIX ain't Windows; it can't make any assumptions about a terminal before knowing what TERM is.
If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: Text formatting is script

Now, you can put them in .profile because at that point TERM is known (even if the term type is "unknown"); you could set and export various tput sequences there.
If it ain't broke, I can fix that.
Khashru
Valued Contributor

Re: Text formatting is script

I put host name in PS1. I want to bold and change the color of the hostnamein the following output.

hpprod:/home/mayub/script :
Bill Hassell
Honored Contributor

Re: Text formatting is script

Bold and colors are text enhancements that don't have any meaning on a dumb terminal. So the first question is: are you using an HP 9000 workstation, that is, an HP-UX computer with a color monitor running Xwindows? If mso, the next question is what program you are running for your text window. Is it xterm, hpterm or dtterm, or something else?

If you are running on a PC, the question still depends on the program you are using to display text. Now the easy answer is to check the man page for terminfo and tput. The following will display several character enhancements:

eval $(ttytype -s)
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 "\t$EE SGR0 $IV BOLD $EE$HB DIM $EE$BL BLINK $EE$HV SMSO $EE$UL SMUL $EE"

Now these enhancements are monochrome (one color, typically white and gray), but some terminal emulators can represent an enhancement with color too.

However, color (specific colors) can be quite complex. Check the terminfo man page, specifically the section on color manipulation. There are hard coded escape sequences that will work with xterm but they completely fail with hpterm and other emulators. That's why the curses library and the terminfo database were created to provide portability.


Bill Hassell, sysadmin
Khashru
Valued Contributor

Re: Text formatting is script

I am using a pc with windowsXP and i use putty for login to the system.
Muthukumar_5
Honored Contributor

Re: Text formatting is script

When you are using with putty to hp-ux platform then you may get bold , dim or etc (monochrome) settings only. It is not possible to get color changes as like linux with bash shell.

--
Muthu
Easy to suggest when don't know about the problem!