Print Bold in Shell scripting

I am printing the following and sending it in an email in a bash script.

echo "#RESULTS FOR `date +%c`#" >> File1.txt

My desired output is to print it in bold:
#RESULTS FOR Mon 16 Nov 2015 03:54:20 PM CST#

Is there a way I can have it printed in bold which sends output in a mail. Please do help.

Thanks

For email, nowadays, if you want it "pretty" you going to send the pretty part as an html encoded block.

Now, that doesn't fix it for shell though.... you might be able to build a filter to translate embedded escapes into something meaningful when printed.

Not much help... but some ideas anyway...

If you store the following values in variable, e.g boldon and boldoff you can do it:-

boldon=`tput smso`
boldoff=`tput rmso`

I might have the wrong bit, this might put on underline or reverse perhaps. I don't have a server to hand to try this on I'm afraid. Can someone correct me if I'm wrong please?

Anyway, you can then use them like this:-

printf "Hello ${boldon}bold${boldoff} world!\n"

I hope that this helps,
Robin

1 Like

You may find the following to be better (?)

boldon=`tput bold`
boldoff=`tput sgr0`

And Robin, thank you for not suggesting hardcoding terminal escapes!!

Hi.

       bold=`tput smso` offbold=`tput rmso`
	    Set  the  shell variables bold, to begin stand-out mode sequence, and offbold, to end
	    standout mode sequence, for the current  terminal.

An excerpt from the man pages here: tput(1) [debian man page]

I didn't see any match for the string sgr -- that might be in man pages for tput in other distributions, systems, etc.

Best wishes ... cheers, drl

1 Like

Doubtful that Debian got this wrong. tput bold and sgr0 date way before Linux for terminfo. With that said, there are some (and popular too) BSD variants still holding on to termcap.