Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to put the bold text in unix ... 2

Status
Not open for further replies.

h3nd

Programmer
Jul 1, 2006
147
AU
Hi guys..

Just simple question, is there any way to put bold text for particular word in unix ..

if in html, something like :
Code:
echo "<b>test</b> again"

and colouring as well,

Thx guys
 
To code this independent of terminal type use tput.

This is from the man page for tput:

4 To set the shell variable bold to the begin standout mode sequence
and the shell variable offbold to the end standout mode sequence,
enter:

bold=`tput smso`

offbold=`tput rmso`

Entering these commands might be followed by the following prompt:

echo "${bold}Name: ${offbold} \c"



HTH,

p5wizard
 
Then substitute "bold" for "smso"

I just cut&pasted from the man page, didn't try it out myself.

bold=`tput bold`

offbold=`tput rmso`

echo "${bold}Name: ${offbold} \c"




HTH,

p5wizard
 
Hi

Yes, I know that was just a copy&paste and also I know what to use to get proper bold.

My question was related to your terminal, if that behaves as the man page predicted. Sorry, if my question was not clear.

Feherke.
 
Heherke,

The man page example uses the bold/offbold variables to hold the escape sequences for "enter/exit standout mode". They chose smso/rmso because perhaps not all terminals/emulators cope in the same fashion with "bold" mode - sometimes the pitch size changes also with bold mode, which makes text-oriented program screens with tables, borders etc. rather awkward to read.

My $0.02


HTH,

p5wizard
 
for colors

numcols=$(tput colors)
# this integer value means you can use color number 0 to (${numcols} -1)

tput colf6 # valid numbers colf0 to colf7 on AIX dtterm
tput colb4 # colb0 to colb7
echo this is a color fg6 on bg4 test
tput sgr0



HTH,

p5wizard
 
Hi p5wizard,

I have tried your code, the bold one is working but not for the offbold.

Here's the script, I've tried :
Code:
#!/bin/ksh

bold=`tput bold`

offbold=`tput rmso`

echo "${bold}Name :${offbold} \n"
echo "where are u going "

But when I tried to send the email regarding that script, the result look like this :
Code:
Name :  

where are u going

do you guys have any idea, how if I want to send the email about result the text keep being bold.

I'm using redhat and my email editor is lotus notes.

Thx guys
 
Those codes generated by tput are terminal control codes; they only work on a terminal.

To put bold in an email you will need to use a different format, either rich text or HTML. There is a FAQ somewhere here about sending HTML emails, if I recall.

Annihilannic.
 
Hi p5wizard,

your code for bold is working but not for offbold
Code:
 bold=`tput bold`

 offbold=`tput rmso`

 echo "${bold}Name: ${offbold} \c"

I've ready the man tput, and I got this :
Code:
bold=âtput smsoâ offbold=âtput rmsoâ

And how I type "â" ??

Thx man,

Could you shed some light ?
 
Try the pair bold/sgr0.

And the ` is a backquote and you seem to have trouble displaying or typing it on your screen...

Another way (works in ksh and bash - does not work in bourne shell though)

bold=$(tput smso)
offbold=$(tput sgr0)

echo "${bold}Name: ${offbold} \c"


HTH,

p5wizard
 
Hi p5wizard and feherke,

your both command worked, but I notice it works only for putty terminal not for xterm.

could you guys explain why ? and what terminal that putty use ?

Thx guys
 
PuTTY emulates an xterm session.

I checked: tput bold /tput sgr0 works in my xterm sessions (both PuTTY and Reflection/X)

Hint: once logged via PuTTY or xterm session, do

echo TERM=${TERM}

both sessions should show the value TERM=xterm. If not, set it to xterm and try again

TERM=xterm
tput bold
echo test bold
tput sgr0
echo test normal


HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top