Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 04-11-2010, 12:54 PM   #1
Registered: Dec 2009
Distribution: Slackware 14
Posts: 282

Rep: Reputation: 64
underlined text in PS1 variable?


I want to underline my user & hostname in the PS1 variable, but I cant seem to do it.

I know that my Xterm can underline text normally, because when I pass Xterm the '+nul' option, then do this:

tput smul; echo underlined text; tput sgr0
it underlines. I just cant seem to get it to work for my PS1 variable, although its quite possible Im doing it incorrectly. has anyone managed to do this, is it possible?

here is my PS1 variable:

PS1='u @\h[\033[0m\]\[\e[m\]\[\033[1;33m\]\w \[\033[0m\]# '

Last edited by clifford227; 04-11-2010 at 12:56 PM.
Old 04-11-2010, 03:14 PM   #2
Registered: Aug 2008
Location: Denmark
Distribution: Fedora, Ubuntu, Solaris
Posts: 35

Rep: Reputation: 19


PS1='\[\033[0m\]\[\033[4;33m\] \u@\h \[\033[0m\]\w# '
Underline is defined by the 4 in the above example.

Or you can try doing the following. First define a few variables:

BLACK=$(tput setaf 0)
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
YELLOW=$(tput setaf 3)
BLUE=$(tput setaf 4)
MAGENTA=$(tput setaf 5)
CYAN=$(tput setaf 6)
WHITE=$(tput setaf 7)
BRIGHT=$(tput bold)
NORMAL=$(tput sgr0)
BLINK=$(tput blink)
REVERSE=$(tput smso)
UNDERLINE=$(tput smul)
Then use these variables in your PS1 setting:

I just tried this on Fedora and Mac OSX

1 members found this post helpful.
Old 04-14-2010, 01:20 PM   #3
Registered: Dec 2009
Distribution: Slackware 14
Posts: 282

Original Poster
Rep: Reputation: 64
thanks Ian, that looks a far eaier way to do it.


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
change PS1 environment variable from c program sagsriv Linux - Newbie 4 03-10-2008 02:39 PM
PS1 environment variable linuxjamil Linux - Networking 1 06-17-2007 12:51 AM
Patch for underlined text on Console? hammernail Linux - Kernel 1 05-09-2006 07:37 PM
PS1 variable wogga Red Hat 2 05-26-2004 06:39 PM
italics and underlined text on PERL randomx Programming 2 03-15-2004 01:01 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:34 PM.

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