LinuxQuestions.org
Review your favorite Linux distribution.
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 04-11-2010, 12:54 PM   #1
clifford227
Member
 
Registered: Dec 2009
Distribution: Slackware 14
Posts: 282

Rep: Reputation: 64
underlined text in PS1 variable?


hi,

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:

Code:
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:

Code:
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
IW2B
Member
 
Registered: Aug 2008
Location: Denmark
Distribution: Fedora, Ubuntu, Solaris
Posts: 35

Rep: Reputation: 19
Hi,

Try

Code:
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:

Code:
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:

Code:
PS1="${BRIGHT}${UNDERLINE}${RED}\u@\h${WHITE}${NORMAL}$ ${PWD}$ "
I just tried this on Fedora and Mac OSX

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

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


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
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


All times are GMT -5. The time now is 02:24 AM.

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