LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-07-2013, 01:36 PM   #1
jefsa
Member
 
Registered: Mar 2012
Posts: 56

Rep: Reputation: Disabled
Using Bold in a bash script


Hello All,

I have tried several attempts at this. This is my issue.
Executing my script returns with first clearing the terminal then followed by the response in BOLD letters. This is what I want.

However, after the response is displayed the command line that follows is also in BOLD print and any other commands I enter are also in BOLD print. What I would like to see is that after the response is returned
in BOLD that the comand line returns to the normal unbold format.

Thanks.

Regards,

Jeff
 
Old 05-07-2013, 01:47 PM   #2
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,260

Rep: Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948
Can't you just undo whatever it is you're doing to make it bold?

Code:
#!/bin/bash

echo not bold
echo -en '\e[1;30m'
echo bold
echo -en '\e[0;30m'
echo not bold

Last edited by suicidaleggroll; 05-07-2013 at 01:49 PM.
 
Old 05-07-2013, 02:52 PM   #3
jefsa
Member
 
Registered: Mar 2012
Posts: 56

Original Poster
Rep: Reputation: Disabled
Hi,

I guess I am not clear.
After my script is ran the terminal is cleared and the script echoes back a response and in this csae the word "Offline".
This is returned in BOLD print on the terminal as desired. However, what follows automatically is the command line
which is also in BOLD from which the script was executed from. I do not want the command line to be returned displayed in BOLD type.

This is shown on the terminal at the upper left corner after the sript is executed:
Offline - (Which is highlighted and expected).
jeff@kiki:~/RICI_Switch2$ - (Which is also highlighted but is not desirable. Any further command entries typed on this line is also
highlighted. I would like this command line to return to its normal unbold state).


Thanks.

Regards,
Jeff
 
Old 05-07-2013, 03:34 PM   #4
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,260

Rep: Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948
Yes, your script is changing the output to bold, which persists after the script exits. Why can't you just change the output back to regular after printing your bolded output before the script exits?
 
Old 05-07-2013, 03:55 PM   #5
parnmatt
Member
 
Registered: Apr 2013
Location: Lancaster
Distribution: Mac OS X
Posts: 38

Rep: Reputation: 7
Quote:
Originally Posted by suicidaleggroll View Post
Yes, your script is changing the output to bold, which persists after the script exits. Why can't you just change the output back to regular after printing your bolded output before the script exits?
From what I can see suicidaleggroll is spot on; it seems that your issue is simple a matter of scope.
To set an output in bold, you're changed the global setting for it.

You should append to your script the code to change it back into regular; so that you are globally changing it back.

Something like
Code:
echo -e "\033[0"
at the end of your script.
 
Old 05-07-2013, 03:59 PM   #6
jefsa
Member
 
Registered: Mar 2012
Posts: 56

Original Poster
Rep: Reputation: Disabled
Hi,

Maybe this is the problem. Could use then a little help with this.

Thanks.

Regards,

Jeff
 
Old 05-07-2013, 04:01 PM   #7
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,260

Rep: Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948Reputation: 1948
Quote:
Originally Posted by jefsa View Post
Hi,

Maybe this is the problem. Could use then a little help with this.

Thanks.

Regards,

Jeff
I already posted code that will switch the output to bold and then back again. Does this not work? Maybe if you posted the relevant parts of your script we could help more.
 
Old 05-07-2013, 04:04 PM   #8
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
It might help if you actually posted the relevant code you're using, you know.

But in any case, just use the '\e[0m' string at the end of every command, or just afterwards, to reset the console.
 
Old 05-07-2013, 06:22 PM   #9
Habitual
LQ Addict
 
Registered: Jan 2011
Location: Youngstown, Ohio
Distribution: LM17.1/Xfce4.11.8
Posts: 7,190
Blog Entries: 10

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by jefsa View Post
Hi,

Maybe this is the problem. Could use then a little help with this.

Thanks.

Regards,

Jeff
https://wiki.archlinux.org/index.php...rompt_and_Bash
 
1 members found this post helpful.
Old 05-07-2013, 08:57 PM   #10
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,604

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
It would seem to be more portable if you used the tput utility.

tput bold - turns it on.
tput sgr0 - turns it off.

You can use things like "bold=$(tput bold)" and "normal=$(tput sgr0)", then when you want bold
you can use "echo $bold .... $normal" where arbitrary text is the "....".

Code:
$ bold=$(tput bold)
$ normal=$(tput sgr0)
$ echo $bold hi there $normal
 hi there
$
Note: the "sgr0" is a reset of special modes, it turns off several of them (including things like superscript - ssupm...).

Read the manpage on tput, and the associated manpage on terminfo. The terminfo page has all the special names for the escape sequences. Using the names improves portability some because different terminal (if you are using them) can use different escape sequences. It is also simpler due to the documentation aspect of using the names.
 
1 members found this post helpful.
Old 05-08-2013, 12:22 PM   #11
jefsa
Member
 
Registered: Mar 2012
Posts: 56

Original Poster
Rep: Reputation: Disabled
To All,

Thank you for your help. This is what I added to the script:
IWhite='\e[0;97m'
Color_Off='\e[0m'
echo -e "${IWhite}Offline"
echo -e "${Color_Off}"

This returned the response in BOLD then returned the follwing command line back to the normal color.

Thanks.

Regards,
Jeff
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Redirected text to be with bold using shell script manojb Linux - Newbie 3 10-29-2012 02:28 PM
LXer: Simple PHP Diff Script - Shows Line Changes in Bold Text LXer Syndicated Linux News 0 05-28-2012 02:01 AM
[SOLVED] print user's input with color+bold+italic in bash roopakl Linux - Newbie 4 04-20-2012 10:04 AM
I want my script output in bold and color fonts gdan2000 Linux - General 6 03-16-2009 07:29 AM
bold Font in Bash Or C AMMullan Programming 5 09-24-2003 05:26 PM


All times are GMT -5. The time now is 09:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration