LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 01-25-2011, 03:24 AM   #1
mike11
Member
 
Registered: Apr 2009
Posts: 222

Rep: Reputation: 17
bash prompt doesn't change from $ to # for su


Hi All,

I'm trying to change the bash prompt and based on the man pages \$ should show a $ which changes to a # for a SU. However, this doesn't happen on my machine, it's $ for both user and SU.
The line in .bashrc is:
export PS1="\u@\h:\w\$"

Thanks in advance.
 
Old 01-25-2011, 03:26 AM   #2
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,604

Rep: Reputation: 446Reputation: 446Reputation: 446Reputation: 446Reputation: 446
Hi,

I assume you mean the prompt for root. You will have to edit root's .bashrc for that. It is located in /root/.bashrc.
Also: Make sure that you use
su -
to switch to root. This will give you a full login shell where root's .bashrc is definitely being sourced.

Last edited by crts; 01-25-2011 at 03:28 AM.
 
Old 01-25-2011, 03:40 AM   #3
mike11
Member
 
Registered: Apr 2009
Posts: 222

Original Poster
Rep: Reputation: 17
Thanks. The root's .bashrc is symlinked to mine. So if I have \$ on my prompt shouldn't this work when changing to su?.
 
Old 01-25-2011, 03:43 AM   #4
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,577

Rep: Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941
Well if it is symlinked to the same thing ... why would it change?? Remembering '\$' means take away the special meanings for the $ sign to give you a $ sign.
 
Old 01-25-2011, 03:58 AM   #5
Kenhelm
Member
 
Registered: Mar 2008
Location: N. W. England
Distribution: Mandriva
Posts: 329

Rep: Reputation: 140Reputation: 140
Try using single quotes instead of double quotes
export PS1='\u@\h:\w\$'

Single quotes preserve the '\' in front of '$'
echo "\u@\h:\w\$"
\u@\h:\w$

echo '\u@\h:\w\$'
\u@\h:\w\$
 
Old 01-25-2011, 03:59 AM   #6
mike11
Member
 
Registered: Apr 2009
Posts: 222

Original Poster
Rep: Reputation: 17
well, the man page says:
Quote:
\$ if the effective UID is 0, a #, otherwise a $
so I su and do echo $EUID and I get 0
which means, as I understand, that the $ should turn into a #. why does the symlink change anything? it's just a pointer to a .bashrc file to run.

note the PS1 line is in double quotes (so it shouldn't be a literal $):
export PS1="\u@\h:\w\$"
 
Old 01-25-2011, 04:19 AM   #7
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,604

Rep: Reputation: 446Reputation: 446Reputation: 446Reputation: 446Reputation: 446
Quote:
Originally Posted by mike11 View Post
well, the man page says:

so I su and do echo $EUID and I get 0
which means, as I understand, that the $ should turn into a #. why does the symlink change anything? it's just a pointer to a .bashrc file to run.

note the PS1 line is in double quotes (so it shouldn't be a literal $):
export PS1="\u@\h:\w\$"
I still think it is better to not link root's bashrc to a user ones. However, if you want to keep it that way then you have to replace the double quotes with single quotes - as suggested be kenhelm. Then you will get the '#' when you switch to root. Make sure to check if there are several branches which set PS1 in your script. If you are not sure which one sets the prompt then make sure to change all of them to single quotes.
 
Old 01-25-2011, 04:23 AM   #8
mike11
Member
 
Registered: Apr 2009
Posts: 222

Original Poster
Rep: Reputation: 17
It's working with single quotes. Thanks.
 
  


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
What to do at the bash-prompt? daav Linux - Newbie 2 10-18-2006 03:52 AM
Bash prompt Hoofty Linux - General 1 03-15-2006 04:54 PM
help! bash command prompt font/color change richiangpan9 Linux - Newbie 3 04-24-2005 11:34 AM
make bash interactive and change prompt DropSig Linux - Newbie 3 05-17-2004 08:16 AM
How do I change the bash prompt in SuSE 8.2 Joey.Dale Linux - Distributions 3 12-08-2003 08:01 AM


All times are GMT -5. The time now is 01:28 PM.

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