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 07-18-2006, 01:28 PM   #1
LQ Newbie
Registered: Jan 2006
Distribution: Fedora 8 & 11, CentOS 5, Debian Etch, Slackware 12.2
Posts: 26

Rep: Reputation: 15
bash prompt problem

Hi all-

quick question:
when I become root, here's my prompt:

[root@host ~] >>

problem is, I interpret "~" as "/home/user", but the shell tells me I'm in /root...this has caused me some confusion at the command line lately...

how can I change the previous prompt to:
[root@host /root] >>
when I su into root?

the pertinent section in my .bashrc is as follows:

1 case $TERM in
2 *term | rxvt)
3 PS1="[\[\e[31;2m\]\u\[\e[0m\]@\h \W]\[\e[31;2m\] >> \[\e[0m\]"
4 export PS1=$PS1"\[\e]0;\u@\H: \w\a\]"
5 ;;
6 *)
7 export PS1="\u@\h \W \$ "
8 ;;
9 esac

...changing the \W to \w in line 3 above has no effect.

thanks for any help!
Old 07-18-2006, 01:36 PM   #2
LQ Guru
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
But ~ means "the home directory of the user", and if your distribution has made /root the home directory for the superuser, you're correct. After all you could, if you wanted to, set /var/log (just an example) to be the home directory of user foo, and then when you were logged in as foo and went to your home directory /var/log, your command prompt would show it as ~.

EDIT: the message in the above example was simply that /home/user is by no means the only place where a user can have it's homedirectory. It's up to the system admin to decide where the home directory resides.

Last edited by b0uncer; 07-18-2006 at 01:37 PM.
Old 07-18-2006, 02:00 PM   #3
Registered: Aug 2005
Location: Juniata College, PA
Distribution: Ubuntu, Slackware
Posts: 67

Rep: Reputation: 15
To answer your question, as far as I know, bash does not have an escape sequence for what you're looking for. However, you could tailor it. The following is a quick and easy sample, but since it will give you the entire working directory, you might want to work on it to shorten up the return.

root's .bashrc:
PS1="[\u@\h $directory]\$ "
When logged in as root and within root's home directory, this will output
[root@host /root]#
(I notice you use >> rather than # to signify root. If you still want to use this, just replace the \$ with >>.)

EDIT: The above isn't correct. See my next response for the explanation...

Last edited by jayemef; 07-18-2006 at 03:45 PM.
Old 07-18-2006, 02:11 PM   #4
Registered: Oct 2002
Location: Charlottesville, VA
Distribution: Ubuntu (home), SLES (work)
Posts: 196
Blog Entries: 1

Rep: Reputation: 30
Quick solution, instead of doing su -, do just an su. This will leave you in current working directory. By doing an su -, it reads the (in this case) roots env, and goes to roots homedir. In that case "~" = /root. If you do a su - user2, than you'll be in /home/user2. An easy redirect would be su - root, then cd ~user. You;ll now be in the /home/user directory.

Old 07-18-2006, 02:25 PM   #5
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
And with all of the above said: you REALLY need to just change your
idea of what ~ stands for. It's "the effective users home directory"
which can be ANYWHERE in the file-system. All you need to know is that
it's "your home". Work-arounds may be all-right, but never rely on them
because there will come a time when you're at a machine you haven't set-up.

Old 07-18-2006, 03:50 PM   #6
Registered: Aug 2005
Location: Juniata College, PA
Distribution: Ubuntu, Slackware
Posts: 67

Rep: Reputation: 15
I made a mistake with my previous reply. What I had done will not work, as pwd is only getting evaluated once. This means that after you start the session, the displayed working directory will not change, regardless of where you move to in the filesystem. I tried putting the command directly into the PS1 variable, but that didn't work either. So I'm not entirely sure if you could accomplish that task manually.

However, I'm fairly certain that \W will work (it displays root for me). Are you certain that after making the change, you re-sourced your .bashrc? You can do this with either the . command or source while in your home directory:
. .bashrc
# or
source .bashrc

That being said, I agree with the advice on changing your concept of ~.

Last edited by jayemef; 07-18-2006 at 04:00 PM.


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
bash prompt subG Slackware 6 01-18-2006 05:43 PM
bash prompt problem akudewan Slackware 7 03-09-2005 08:21 AM
bash prompt problem jackpal Linux - Software 6 02-04-2004 12:37 PM
Bash Prompt mandraketux Mandriva 2 11-28-2003 11:05 PM
bash problem: no prompt xyfan Linux - General 6 11-25-2003 12:15 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:17 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