Operating System - Linux
1753786 Members
7538 Online
108799 Solutions
New Discussion юеВ

Re: script output in BOLD

 
SOLVED
Go to solution
Alan Meyer_4
Respected Contributor

script output in BOLD

I should know this, but I don't... How do I make portions of the output of a shell script to appear BOLD on the screen as well as print in BOLD when redirected to the printer?

ie... (text shown in CAPS are to be bold)

now is the TIME for all good men

TO COME TO THE AID OF THEIR COUNTRY...

" I may not be certified, but I am certifiable... "
11 REPLIES 11
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: script output in BOLD

echo "now is the \c"
tput bold
echo "TIME\c"
tput rmso
echo " for all good men"
tput bold
echo "TO COME TO THE AID OF THEIR COUNTRY..."
tput rmso

Man tput, terminfo for details.
If it ain't broke, I can fix that.
Pete Randall
Outstanding Contributor

Re: script output in BOLD

Alan,

Try a man on "tput".


Pete

Pete
Rodney Hills
Honored Contributor

Re: script output in BOLD

I've set the following in my script-
export ttybold=`tput bold` ; export ttynorm=`tput rmso`

Then I can do
echo "now is the ${ttybold}TIME${ttynorm} for all good men"

HTH

-- Rod Hills
There be dragons...
Alan Meyer_4
Respected Contributor

Re: script output in BOLD

how do you incorporate that into a printf statement like:

printf "%-10s: %-10s %-16s %-16s %-s\n" $NODE $LVLNB $PVD1 $PVD2 $NOTE

where the whole line is to be BOLD? but nothing before or nothing after?
" I may not be certified, but I am certifiable... "
Sandman!
Honored Contributor

Re: script output in BOLD

tput smso
printf "%-10s: %-10s %-16s %-16s %-s\n" $NODE $LVLNB $PVD1 $PVD2 $NOTE
tput rmso
James R. Ferguson
Acclaimed Contributor

Re: script output in BOLD

Hi Alan:

How about :

# XON=`tput bold`;XOFF=`tput rmso`;printf "%sI said %s %-s\n" ${XOFF}

Regards!

...JRF...

Alan Meyer_4
Respected Contributor

Re: script output in BOLD

Doing it in echo mode works great, but,...

the suggestions for incorporating it into a printf have not worked.
" I may not be certified, but I am certifiable... "
A. Clay Stephenson
Acclaimed Contributor

Re: script output in BOLD

Oh, I should have read your post more carefully. The sequences needed to bold output to the terminal have nothing to do with those that are sent to the printer -- or if they do, it's purely accidental.

However, you can create terminfo entries for printers as well and invoke tput with a -T option to indicate the printer type. Note that you will need to know the printer model and have a terminfo entry for each type. The command that converts a text file into a terminfo entry is 'tic'; 'untic' does the reverse. Man tic and untic for details. You are now getting into areas that UNIX ain't real good at doing. The application is supposed to take full control of this kind of printer output.
If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: script output in BOLD

and the key to making your printf's work is them there quotes -- which is always good shell programming practice.

typeset BOLD=$(tput bold)
typeset NORMAL=$(tput rmso)
typeset VAR1="This is some text; "
typeset VAR2="this here is some more text."

printf "%s%s %s%s\n" "${BOLD}" "${VAR1}" "${VAR2}" "${NORMAL}"

printf "(Normal) %s %s\n" "${VAR1}" "${VAR2}"
If it ain't broke, I can fix that.