Quote:
Originally Posted by David the H.
I'm not exactly clear here. Do you want the root user to have a '#' prompt and other users to have a '$'?
|
Yes, that's correct. This is standard bash prompt ideology, the use of a "#" for root, as opposed to "$" for normal users.
Quote:
Originally Posted by David the H.
/etc/bashrc is the system-wide bash settings file. If you simply change the prompt there, then of course you're going to see it show up in all consoles, including root.
You have two choices. First, you can remove the line from /etc/bashrc and place it instead in the individual ~/.bashrc files of only the users you want to change. (Note that root also has it's own 'home' folder, /root, and its own .bashrc.
|
It's my understanding that each time a user logs in, the /etc/bashrc is executed, then the local user's .bashrc is read. Therefore, PS1 in ~/.bashrc will take precidence over PS1 in /etc/bashrc. With that, even when I place 'PS1="\$"' in root's .bashrc, it still shows '$ '.
In the PROMPTING section of the bash man page, \$ is described as having the following function:
Code:
\$ if the effective UID is 0, a #, otherwise a $
If this is different from the function I think it is, please clarify this.
Quote:
Originally Posted by David the H.
Your second choice is to use an 'if' statement to detect when the user is root. Something like this:
Code:
if [ "`id -u`" -eq 0 ]; then
PS1='# '
else
PS1='$ '
fi
|
I have a function similar to yours that does what I want. But this is not optimal, and for learning purposes I would like to know why a simple 'PS1="\$"' doesn't display "#" for root.