Make bold chars in UNIX

Hi all,

I want to make the string as bold in unix.
is there any way to acheive this?

thanks in advance.

it depends on your terminal and UNIX variant.

you can try:

or better -

Just to add to agent.kgb...

You could do:

b=`tput bold`
c=`tput sgr0`
echo "Hello ${b}ShekhaReddy${c}. Welcome to the forums."
1 Like

On linux, you may consider man console_codes as well. On (Free)BSD, tput bold doesn't work. You need to refer to the terminal capabilities, found in e.g. /etc/termcap . Try tput md .

Or try:

printf '\e[1m%s\e[0m\n' "Hello there"

You really do *not* want to hardcode terminal escapes since they are terminal dependent. Better to query capabilities.

Sad to hear that FreeBSD stayed with the outdated termcap format. Supposedly if you add ncurses devel support to FreeBSD you'll get terminfo. Still it's sort of sad really.

I believe OpenBSD and NetBSD moved forward. It's strange to me that FreeBSD stayed behind on this.

Thanks for your replies.

I found the below codes are working in command prompt. i.e

echo "one $(tput bold) two$(tput sgr0) three"

tput bold is to make bold text and tput sgr0 is to bring normal mode.
When i try with this code it is working fine in command prompt.
But i want to make this bold chars in flat file.
I mean my target is flat file. While writing the out put to flat file, it needs to make bold in headings .This needs to be achieve via informatica .

Please help me on this.

thanks in advance....

Woh!!! Didn't know flat files via informatica had styling capabilities like a word processor.

Uhm... "flat file" = "textfile"?
Textfilebold != Terminalbold.

Unless of course you're talking about MD or HTML :stuck_out_tongue:

<b>html bold</b>
##MD bold##

Just got up, but if you tell this one to use ncurses so he has bold for his scripts.. you could use TUI as well.
Though, its 'termcap' too, isnt it?

But at least this kind of code works on Arch, Deb, Freebsd and RH.
Couldnt verify for Solaris just yet, but i'm quite sure it'll work there just fine too.

:)  $ . tui

+  $ echo "${TUI_FONT_BOLD}Hello${TUI_RESET}"
\033[1mHello\033[0m

  $ printf "${TUI_FONT_BOLD}Hello${TUI_RESET} $USER"
Hello sea
echo $TUI_FONT_<TAB>
$TUI_FONT_BOLD        $TUI_FONT_INVERT      $TUI_FONT_STROKE      $TUI_FONT_UNDERSCORE  

hth

A flat file is just what it is (generally speaking)... it's text. I you don't plan to use a text editor to view the file, then perhaps what you need to output is something like HTML instead (?). That way you have some markup control than can be interpreted by the end device. If you wan to go totally old school though there is also nroff/troff. Basically the format that raw "man pages" are in. Yep... it's old, but still used.... and in some ways, can be better than something like HTML just because of the number of end device handlers out there (including ones for taking the format to HTML).

Does that make sense? Things like "bold" are terminal (viewing or output device) specific.

---------- Post updated at 09:42 AM ---------- Previous update was at 09:38 AM ----------

Well... because ncurses support both dbs... technically they'll tell you that you must call it a "termcap" package. But it does both. I only mentioned it because the FreeBSD mailling lists indicated that it's one way to get a terminfo db on FreeBSD.

Hmm :confused:
When i search for ncurses on youtube, i see plenty of C-like code, which doesnt look script'ish as php or java script for example.
Though, it could be perl... but then again, the TO asked for a script, and to my believe perl is out of that (general usage) range.

Trying to say:
With my knowledge, to my understanding ncruses seems like its providing a programming language API which then needs to be compiled - and therefor is not a script. (please correct me if i'm mistaken on this)
Furthermore, tput bold is part of ncurses support utilities, which was in this thread said to be not working on some systems.

$ yum provides tput
Loaded plugins: langpacks
ncurses-5.9-16.20140323.fc21.x86_64 : Ncurses support utilities
Repo        : fedora
Matched from:
Filename    : /usr/bin/tput

Which makes my confusion - perfect :wink:

Thank you

yes ncurses is a binary package. On FreeBSD to get a terminfo db, you need the devel part as well.

Scripts use binaries. In *ix it's essential.... scripting gives power to use those binary programs in strange and fabulous ways to do truly interesting things.

---------- Post updated at 11:19 AM ---------- Previous update was at 11:18 AM ----------

Oh.... and tput doesn't have to part of ncurses. It's just that ncurses is a popular package and where it's found on many systems nowadays.

---------- Post updated at 11:20 AM ---------- Previous update was at 11:19 AM ----------

People in general don't seem to care much for terminals anymore... sad, but true.

Well, it is provided as an alternative in this thread (since it will work in many terminals) in case tput does not work as expected, since it is not required by the standards, at least it is only required to support clear, init and reset:

OPERANDS

The following strings shall be supported as operands by the implementation in the POSIX locale:

clear
      Display the clear-screen sequence.
init
      Display the sequence that initializes the user's terminal in an implementation-defined manner.
reset
      Display the sequence that resets the user's terminal in an implementation-defined manner.

If a terminal does not support any of the operations described by these operands, this shall not be considered an error condition.

tput: operands

so tput is not guaranteed to always produce the right result...

tput POSIX maybe not, because POSIX != *ix (as weird as that sounds). But tput (with terminfo) will work on Solaris, HP-UX, AIX, Linux, NetBSD, OpenBSD, SVR4 implementations, SVR3 implementations and most all SVR2 implementations.

Which is why I was surprised that FreeBSD didn't go that way.

So... really, I think it's probably best to say tput with terminfo capabilities doesn't work on FreeBSD but works (practically speaking) everywhere else :slight_smile:

1 Like

Thanks, good to know that in practice it is much more usable than the POSIX standard suggests...

Misunderstanding, yes its a binary package, as most packages are.
And that one calls binaries from a script is obvious.
Calling a binary from another binary isnt that 'nice'.

But me (was) talking about how to use ncurses, as it seems (to me) one must do binaries too, which isnt scripting - which is where the TO wanted to use bold text (though that would be tput =! ncurse).
Hope you understand me?
Maybe i have gotten just all the wrong youtube videos... but in all of those i watched, NONE of the shown code was bash/csh/ksh!

I love terminals (and scripting), thats why i wrote TUI, as another style of ncurses, and actualy be usable within scripts, without needing to compile it first.

Back on topic... ncurses is a package which happens to contain a version of tput (for places that don't have tput). Thus you just need to call tput with a capability string (from the command line or script) and capture it's output (well for most things tput does).

Yes.. ncurses (library) provides a way of building sophisticated TUIs on terminals (things like windows, etc..) and for that, you need to write a program. But the package does contain some other items (like tput).