I'm currently trying to modify my terminal to have the prompt displayed in a different colour than the whole rest of the shell, and I would like to make it white for normal users and red for root.
I would like to do so on both, an OS X 10.10 Desktop and an Ubuntu 14.10 Server.
The only way I know of doing this is to modify $PS1
.
And to do so, I would have to put it in a script that the shell sources on login, right?
However, on OS X the root user's shell is /bin/sh
, and although that is actually bash, it does not source any login script unless a full login is invoked.
Now I know about su - <user>
, but I need it to work with just su <user>
.
I could change the root user's login shell, but I'd rather not.
Here's what I found out so far:
bash
invoked as bash
and logged in as su -
sources:
/etc/profile
/etc/bashrc
~/.profile
bash
invoked as bash
and logged in as su
sources:
~/.bashrc
bash
invoked as sh
and logged in as su -
sources:
/etc/profile
/etc/bashrc
~/.profile
bash
invoked as sh
and logged in as su
sources nothing at all.
I also tried hijacking $PROMPT_COMMAND
, but that gets emptied on invoking su
.
On the bash manual it says:
Invoked with name sh
If Bash is invoked with the name
sh
, it tries to mimic the startup behavior of historical versions ofsh
as closely as possible, while conforming to the POSIX standard as well.When invoked as an interactive login shell, or as a non-interactive shell with the
--login
option, it first attempts to read and execute commands from/etc/profile
and~/.profile
, in that order. The--noprofile
option may be used to inhibit this behavior. When invoked as an interactive shell with the namesh
, Bash looks for the variableENV
, expands its value if it is defined, and uses the expanded value as the name of a file to read and execute. Since a shell invoked assh
does not attempt to read and execute commands from any other startup files, the--rcfile
option has no effect. A non-interactive shell invoked with the namesh
does not attempt to read any other startup files.When invoked as
sh
, Bash enters POSIX mode after the startup files are read.
So... is there any way me to set $ENV
?
Simply setting it before invoking su
has no effect.
Or is there any other way for me to modify $PS1
when the UID changes (full login or not), without having to use su - ...
, changing the root user's login shell or messing with su
/bash
?
sh
and logged in assu
[notsu -
] sources nothing at all”?