LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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, 07:35 AM   #1
akudewan
Member
 
Registered: Apr 2004
Location: India
Distribution: Ubuntu
Posts: 364

Rep: Reputation: 31
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, 08: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 08:11 AM.
 
Old 03-06-2005, 08:08 AM   #3
keefaz
LQ Guru
 
Registered: Mar 2004
Distribution: Slackware
Posts: 6,552

Rep: Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872Reputation: 872
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, 08: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, 01: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: 50
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, 03:29 AM   #6
akudewan
Member
 
Registered: Apr 2004
Location: India
Distribution: Ubuntu
Posts: 364

Original Poster
Rep: Reputation: 31
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, 04: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, 07: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



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 03:35 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
Open Source Consulting | Domain Registration