LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
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 07-18-2006, 12:28 PM   #1
bjharker
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, 12:36 PM   #2
b0uncer
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 12:37 PM.
 
Old 07-18-2006, 01:00 PM   #3
jayemef
Member
 
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:
Code:
directory=`pwd`
PS1="[\u@\h $directory]\$ "
When logged in as root and within root's home directory, this will output
Code:
[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 02:45 PM.
 
Old 07-18-2006, 01:11 PM   #4
peter72
Member
 
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.

Pete
 
Old 07-18-2006, 01:25 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 22,962
Blog Entries: 11

Rep: Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865Reputation: 865
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.


Cheers,
Tink
 
Old 07-18-2006, 02:50 PM   #6
jayemef
Member
 
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:
Code:
. .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 03:00 PM.
 
  


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


All times are GMT -5. The time now is 01:23 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration