Bash – How change prompt of subshell

bashpromptzsh

I'm trying to create a simple script that, among other things, will create a subshell:

#!/bin/sh

# setup

"${@:-$SHELL}"

# teardown

The question is: I need to change the default prompt, so for example:

$ # default shell
$ ./myscript
(myscript) $ # subshell
(myscript) $ exit
$

I tried to change PROMPT and PS1, but none of these works. How can I do that?

PS.: I need a solution that works both on Bash and ZSH, if possible.

Best Answer

I think you can create a subshell with a different prompt like this:

$ bash --rcfile <(echo "PS1='subshell prompt: '") -i

Example

Current env:

$ bash --rcfile <(echo "PS1='subshell prompt$ '") -i

In sub shell:

subshell prompt$ echo hi
hi
subshell prompt$ exit
exit

Back to original shell:

$ 
Related Question