Skip navigation
This discussion is archived

Change bash prompt for root user (Leopard)

6080 Views 10 Replies Latest reply: Nov 28, 2007 1:34 PM by Tina Siegenthaler RSS
Tina Siegenthaler Calculating status...
Currently Being Moderated
Nov 28, 2007 7:06 AM
Hi all

This is probably a stupid question but...
I don't like the new shell prompt in Leopard (I'm not really interested in which bash version I'm using, I'd rather see my working directory), so I changed it for my "normal" user in ~/.bash_profile. I'd like to change the prompt for the root user, too, but where can I do that? I added a .bash_profile and a .bashrc file (with my prompt definition in them of course) to /var/root, but this didn't have any effect.

Thanks, Tina
G5 Dual 1.8, 23'' Cinema Display, Mac OS X (10.4.5), iMac G4/800, iBook G3/700, G4/400, iBook G3/366, iMac G3/233, PM 7200, Mac SE
  • jarik Calculating status...
    Currently Being Moderated
    Nov 28, 2007 7:25 AM (in response to Tina Siegenthaler)
    Do you login as root, or do you sudo bash? For me, when I sudo bash my PS1 gets inherited to the new shell.

    "sudo -H bash" changes HOME to /var/root (reads .bashrc)
    "sudo -i" simulates login (reads .bash_login)
    MacBook Pro, Powerbook G4, Mac OS X (10.5.1)
  • Mihalis Tsoukalos Level 4 Level 4 (2,015 points)
    Currently Being Moderated
    Nov 28, 2007 7:24 AM (in response to Tina Siegenthaler)
    Tina,
    you can also try /etc/bashrc.

    Mihalis.
    Dual G5 @ 2GHz, Mac OS X (10.5.1), http://widgetbook.blogspot.com
  • jarik Level 4 Level 4 (1,005 points)
    Currently Being Moderated
    Nov 28, 2007 12:57 PM (in response to Tina Siegenthaler)
    Try the line
    PS1="\ \h \ \W \ \$ "

    except that you put the two backslashes together without the space in between. I had to add those to fool the automatic formatting system.

    This should give you a hash when effective uid is 0.

    I'm curious why it's not getting inherited as it is with my setup? Could you mv the new .bashrc and .bash_login out of the way and just do a plain sudo bash, then

    <pre>echo $PS1</pre>

    Also, how is PS1 set in your own .bashrc and .bash_login?

    Message was edited by: jarik

    Actually, it's not being inherited: instead my own .bashrc gets reread when I sudo bash (bash reads .bashrc from $HOME when starting unless it's a login shell, and $HOME is not being changed by default with sudo). So, I am suspecting that your .bashrc has some control structure to it and the PS1 setting line is not being executed. You could add some debugging to it, maybe a set -x in the beginning.

    Message was edited by: jarik
    MacBook Pro, Powerbook G4, Mac OS X (10.5.1)
  • jarik Level 4 Level 4 (1,005 points)
    Currently Being Moderated
    Nov 28, 2007 1:07 PM (in response to Tina Siegenthaler)
    That's because /etc/bashrc only gets read for login shells, from /etc/profile.
    MacBook Pro, Powerbook G4, Mac OS X (10.5.1)
  • jarik Level 4 Level 4 (1,005 points)
    Currently Being Moderated
    Nov 28, 2007 1:31 PM (in response to Tina Siegenthaler)
    .bash_profile (or .bash_login) is only read if the shell is a login shell. Do a shopt | grep login_shell to find out if it is. So when the new bash for sudo starts it won't find any bashrc to read, and it won't touch .bash_profile or .bash_login. You can do a simple

    <pre class=command>. ~/.bash_profile</pre>

    from your .bashrc so you don't have to keep two files up-to-date. PATH is probably inherited from your original shell. BTW, there is no need to export PS1 that I know of.

    Let's see if you can kick me up into Level 3 :-D

    Message was edited by: jarik

    Message was edited by: jarik
    MacBook Pro, Powerbook G4, Mac OS X (10.5.1)

Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.