$PS1 changes when using su command

Discussion in 'macOS' started by drobati, Jun 22, 2009.

  1. drobati macrumors newbie

    Joined:
    Jun 11, 2009
    #1
    When using su admin, the prompt becomes

    Code:
    bash-3.2$
    I had thought thought that perhaps that was because my .bash_profile file in /Users/admin wasn't configured.

    I copied over a similar file from my standard account /Users/drobati/.bash_profile

    Closed terminal and reopened.

    Typed in su admin again and nothing changed.

    I'm aware that /etc/profile calls to /etc/bashrc. Unfortunately the variable within /etc/bashrc is PS1='\h:\W \u\$ '

    This doesn't equal the prompt im currently getting. This prompt equals '\s-\v\$ '

    Where is the $PS1 variable stored when su is used in a standard session? Is there a command that can tell me where $PS1 is being changed?
     
  2. wrldwzrd89 macrumors G5

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #2
    When you use the su command to switch users, the prompt you get is the prompt of the user you switched to. Sounds obvious after you realize that this is the case, but it'll trip up UNIX newbies all the time.
     
  3. sidewinder macrumors 68020

    sidewinder

    Joined:
    Dec 10, 2008
    Location:
    Northern California
    #3
    Use "su -l" or "su -" so it simulates a full login. Otherwise the .bash_profile is not read. If you create a file called ".bashrc" at the root level of the "admin" account, and put the PS1 string in there, it will be read and the defined prompt will be used.

    S-
     
  4. sidewinder macrumors 68020

    sidewinder

    Joined:
    Dec 10, 2008
    Location:
    Northern California
    #4
    Not true if you use just "su".

    S-
     
  5. wrldwzrd89 macrumors G5

    wrldwzrd89

    Joined:
    Jun 6, 2003
    Location:
    Solon, OH
    #5
    D'oh! Thanks.
     
  6. drobati thread starter macrumors newbie

    Joined:
    Jun 11, 2009
    #6
    Thanks. I had said I made a .bash_profile file and it didn't work so the response was confusing.

    Both solutions work perfect.
     

Share This Page