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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Echo BOLD chacters in a script

Status
Not open for further replies.

Tison

Programmer
May 12, 1999
216
CH
How do I write a shell script that will toggle between BOLD and NORMAL to create a banner like this ;<br>Welcome to the&nbsp;&nbsp;- this line normal script<br>&nbsp;&nbsp;&nbsp;IT&nbsp;&nbsp;ZONE&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;- this line uppercase bold<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;maybe even underlined.<br>I guess I want to know how to turn bold on and off within a script.<br><br>Any ideas ?<br><br><br>
 
You can use <FONT FACE=monospace><b>tput bold</font></b> to turn on bold and <FONT FACE=monospace><b>tput sgr0</font></b> to turn it off again; you can do lots of other things with <FONT FACE=monospace><b>tput</font></b> as well, take a look at the man page. <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
i usually use korn shells for my scripting, have done for quite a while now.<br><br>In Korn shells, you can define diffrent types of characters, and their position.<br><br>Write the following script:<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+++&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>#!/bin/ksh<br>echo &quot;Screen Test...&quot;<br>echo &quot;<font color=red>^</font>[[1m Screen typo 1&quot;<br>echo &quot;<font color=red>^</font>[[2m Screen typo 2&quot;<br>echo &quot;<font color=red>^</font>[[3m Screen typo 3&quot;<br>echo &quot;<font color=red>^</font>[[4m Screen typo 4&quot;<br>echo &quot;complete.&quot;<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+++&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>Now, before you copy all this text into a script, note the follwing:<br>where i placed the <font color=red>RED</font> writing, you must know that it wasnt 'EXACT' characters. They were control characters.<br>EG: for the line...<br>&nbsp;echo &quot;<font color=red>^</font>[[1m Screen typo 1&quot;<br>the character controls are:<br><br>i&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# -Insert-<br>&lt;CTRL&gt;+V&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# Character -Insert-<br>[&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# Giving total of ^[[<br>... then the rest in normal characters.<br><br>Every diffrent emulation and version of linux gives diffrent results. I'm not sure how many types of character sets there are, but if you know about positioning on a screen within a korn shell, you will know what i mean.<br><br>Please feel free to mail me, and i can mail you a short script, about placing characters where, and in a format.<br><br><br>Over and out, Karl.<br><br> <p>Karl Butterworth<br><a href=mailto:karl_butterworth@ordina.co.uk>karl_butterworth@ordina.co.uk</a><br><a href= > </a><br><i>I'm slim shadey, yes i'm the real shadey, all you other slim shadeys are just imitating; so wont the real slim shadey please stand up, please stand up, please stand up!</i>
 
Karl,<br><br>Your approach (embedding control characters in a script) works fine as long as the script will only ever run on one type of terminal/emulation. Terminal control chars are very terminal specific.<br><br>The reason I suggested tput was that it understands terminal types and does the right thing for each terminal type. <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Well, like i said, <br><br>...Every diffrent emulation and version of linux gives diffrent results...<br><br>I know, but it's the only way i know how to do it. And it was very useful to me before, <br><br>But by all means, please can you elabourate on the tput method.<br><br>Thanks greatly, Karl. <p>Karl Butterworth<br><a href=mailto:karl_butterworth@ordina.co.uk>karl_butterworth@ordina.co.uk</a><br><a href= > </a><br><i>I'm slim shadey, yes i'm the real shadey, all you other slim shadeys are just imitating; so wont the real slim shadey please stand up, please stand up, please stand up!</i>
 
ok.<br><br>it's called in a ksh script like this<br><FONT FACE=monospace><b><br>tput bold<br>print &quot;hello&quot;<br>tput sgr0<br>print &quot;world&quot;<br></font></b><br>or, if you wish, you can embed the control codes that tput returns like this<br><FONT FACE=monospace><b><br>bold_on=$(tput bold)<br>bold_off=$(tput sgr0)<br>print &quot;${bold_on}hello$bold_off&quot;<br></font></b><br><br>My original reply was a bit short - sorry<br> <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top