Dave's Brain

Browse - Programming Tips - How can I underline and bold from a shell script?

Date: 2012apr24
OS: Linux
Keywords: bash

Q.  How can I underline and bold from a shell script?

A.  Use the tput command.  Like this:

# Bold is SO=Stand Out BOLDON=`tput smso` BOLDOFF=`tput rmso` echo ${BOLDON}hello${BOLDOFF} ULON=`tput smul` ULOFF=`tput rmul` echo ${ULON}hello${ULOFF}
tput outputs the right codes for your current terminal. So don't save its output and use that somewhere else. It only takes a second to run the four tputs anyhow. You can use tput from other languages too. Read its output with popen(). If you want to get really fancy, in C/C++ check out ncurses.
dnf install ncurses-devel
https://www.google.com/search?q=ncurses The Blessings library looks nice for Python.

Add a comment

Sign in to add a comment
Copyright © 2008-2018, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.