The PS1
shell variable should be set in ~/.bashrc
for the bash
shell as that is the initialisation file that is read for interactive shell sessions.
Note that this variable is a shell variable, not an environment variable (it does not make sense to let child processes inherit its value, and it's only the current shell that uses it). It therefore does not need to be exported with export
.
Related:
You shouldn't need to start bash
from any of the shell's startup files. Starting a particular shell from ~/.profile
(or the corresponding file related to your login shell) may possibly be warranted if the system that you're running on does not allow you to change your login shell. Care should be taken to not start the other shell if that is the shell already executing the file though, or you may end up in an infinite loop of sorts.
The exec
code that you add to your ~/.bash_profile
should never be needed. I suppose it's a way of getting ~/.bashrc
to be parsed (it starts an interactive shell, and interactive bash
shells read ~/.bashrc
). A better way of doing that would be to have one of the files source the other, for example using this in ~/.bash_profile
:
if [[ -f $HOME/.bashrc ]]; then
source "$HOME/.bashrc"
fi
Then set PS1
in ~/.bashrc
(there should be no need to touch HOME
or TERM
).
The other thing that the command does is to clean out all other environment variables using env -i
. Unless you have very specific reasons to do this, you should not do that from your ordinary shell startup files.
exec env -i HOME=${HOME} TERM=${TERM} PS1='\u:\w\$ ' /bin/bash
.A mistake or any other possible purpose. – Israr Oct 28 '19 at 09:01PS1
from.bashrc
. Sure, anything like that would need to be shell-specific anyway, but it's not that impossible an idea, IMO. Prepending some fixed string to an existingPS1
would also work for many shells (or you could just make it configurable) – ilkkachu Oct 28 '19 at 10:03PS1
when launched non-interactively, doing that gets somewhat hard. – ilkkachu Oct 28 '19 at 10:04PS1
in the environment, always. – Kusalananda Oct 28 '19 at 10:25.bash_profile
, when it is not showing me up in Terminal in any mode whether it is login/nologin or interactive? – Israr Oct 28 '19 at 21:22bash
shell session with a clean environment usingenv -i bash
at any time. There is no point in doing it from~/.bash_profile
by default. I believe this was what user muru alluded to, but with different words. – Kusalananda Oct 28 '19 at 22:02~/.bash_profile
for all one's shells seems counterproductive, as it deletes environment variables set up by system initialization files in/etc
. – Kusalananda Oct 29 '19 at 09:10