LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices

Reply
 
Search this Thread
Old 03-06-2005, 08:35 AM   #1
akudewan
Member
 
Registered: Apr 2004
Location: India
Distribution: Ubuntu
Posts: 364

Rep: Reputation: 30
bash prompt problem


I'm sure this is asked very often, but I just cant figure it out. Basically, I want my pwd to be shown in my prompt. This is the .bashrc and .bash_profile in my home directory

.bashrc -->
Code:
alias ls='ls --color'
PS1="\u@\h:\w\$ "
.bash_profile-->
Code:
if [ -f ~/.bashrc ]; then
    source ~/.bashrc
fi
This works for normal users, but when I adopted this for root, it still showed a Dollar sign and not a hash (#)

How do I adapt it for root? Also, can I change the prompt globally by editing /etc/profile ?
 
Old 03-06-2005, 09:07 AM   #2
Oliv'
Senior Member
 
Registered: Jan 2004
Location: Montpellier (France)
Distribution: Gentoo
Posts: 1,014

Rep: Reputation: 36
Hello,

if that does not work for root it probably comes from your /root/.bashrc or /root/.bash_profile which tells PS1 variable to overwrite # prompt.
Unless your /etc/profile don't do the usual uid comparison:
Code:
if [ $EUID -eq 0 ] ; then

Last edited by Oliv'; 03-06-2005 at 09:11 AM.
 
Old 03-06-2005, 09:08 AM   #3
keefaz
Senior Member
 
Registered: Mar 2004
Distribution: Slackware
Posts: 4,617

Rep: Reputation: 136Reputation: 136
By default the prompt is set as you wish (PS1='\u@\h:\w\$ ') in /etc/profile

When you log as root, does the prompt is set correctly in console and not in
x terminal ?
 
Old 03-06-2005, 09:09 AM   #4
Oliv'
Senior Member
 
Registered: Jan 2004
Location: Montpellier (France)
Distribution: Gentoo
Posts: 1,014

Rep: Reputation: 36
Hello,

if that does not work for root it probably comes from your /root/.bashrc or /root/.bash_profile which tells PS1 variable to overwrite # prompt.
Unless your /etc/profile don't do the usual uid comparison:
Code:
if [ $EUID -eq 0 ] ; then
   export PS1=...
fi
Oliv'
 
Old 03-07-2005, 02:16 AM   #5
shilo
Senior Member
 
Registered: Nov 2002
Location: Stockton, CA
Distribution: Slackware 11 - kernel 2.6.19.1 - Dropline Gnome 2.16.2
Posts: 1,132

Rep: Reputation: 49
I don't have an answer, but I do want to chip in that it is a very nice feature having the different prompts for root and for users. Gives you a nice indicator of how much you can mess things up at any given time.
 
Old 03-07-2005, 04:29 AM   #6
akudewan
Member
 
Registered: Apr 2004
Location: India
Distribution: Ubuntu
Posts: 364

Original Poster
Rep: Reputation: 30
OK, I created a .bashrc file in root's home directory that has the following contents:

alias ls='ls --color'
PS1="\u@\h:\w\$ "

Thats all, and the problem was solved. Thanks for all the help
 
Old 03-07-2005, 05:38 AM   #7
Grunthos
LQ Newbie
 
Registered: Mar 2005
Location: Sydney, Australia
Distribution: Slackware 10.2
Posts: 20

Rep: Reputation: 0
more on bash prompts

further to that I have found 2 extra things very helpful.

Firstly:

using \W instead of \w will give you the last part of the path so as not to take up the whole width of the screen.

Secondly:

I try to make the prompt for root a different colour (mainly red) than the normal colour as a reminder that I am still able to screw the system up with a careless command.

I do this with the following *8)

export PS1='^[[1;31m\h \W\$ ^[[0m'

I generally use id or whoami if i need to know who i am logged in as its a personal choice.

^[ <== <ctrl+v><esc>, then you add the second [ . You should remember to close the colour with ^[[0m or you will change ALL text


hope this is helpful to someone

-Grunthos
 
Old 03-09-2005, 08:21 AM   #8
Oliv'
Senior Member
 
Registered: Jan 2004
Location: Montpellier (France)
Distribution: Gentoo
Posts: 1,014

Rep: Reputation: 36
to customize your bash prompt see also this howto: http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/
 
  


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 05:43 PM
bash prompt problem jackpal Linux - Software 6 02-04-2004 12:37 PM
help with bash prompt everythingand2 Linux - Newbie 7 12-06-2003 05:28 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


All times are GMT -5. The time now is 06:32 PM.

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