0

I'm trying to set PS1 as "KeepPrompt", and prevent it from being changed while entering into a subshell. To do that I entered the following:

user@host:~$ echo $SHLVL 
user@host:~$ 1 
user@host:~$ export PS1="KeepPrompt: "
KeepPrompt:  
KeepPrompt: echo $SHLVL
KeepPrompt: 1
KeepPrompt: bash 
user@host:~$ 
user@host:~$ echo $SHLVL 
user@host:~$ 2

As you see when I try to create a new subshell, the PS1 definition doesn't survive entering into the new shell. Why is it so?

1
  • Absolutely right. +1 for being so informative!
    – Dsaki
    Jul 14, 2020 at 14:15

1 Answer 1

4

When you initialize a (bash) (sub)shell several files are sourced.

For me (and I think that is default in Ubuntu) PS1 will be overwritten by /etc/bash.bashrc and ~/.bashrc.

Also, /etc/profile sets $PS1, but only when it is empty.


Best would be to add this at the end of your .bashrc:

PS1="KeepPrompt: "

Not the answer you're looking for? Browse other questions tagged .