Bash – Changing the PS1 on an interactive bash subshell easily

bash

I have a situation where I need to provide a subshell to a user mid-way through a longish process. I would like to change the prompt to remind the user that they are in a special subshell and haven't gone through the rest of the process yet. I thought that this would do what I want…

echo "PS1='foo:'" | bash -i

But when I enter that line, this is the output I get

me@mercury:~$ PS1='foo:'
foo:exit
me@mercury:~$ 

Is there a simple way around this? I could writeup my own custom bashrc… but I'd prefer to preserve the user's usual bash-shell setup.

Best Answer

You can use process substitution to essentially make a ~/.bashrc that only exists for the bash -i invocation like so:

 bash --rcfile <(echo "PS1='foo: '") -i
Related Question