익명 17:51

Open new xterm window with different PS1

Open new xterm window with different PS1

I'm trying to open a new xterm window with a different PS1. I've tried:

xterm -e '/bin/bash -i -l -c "export PS1=foo"'

This immediately closes xterm. So I tried:

xterm -hold -e '/bin/bash -i -l -c "export PS1=foo"'

which keeps xterm open, but I can't use it, i.e.: there is no prompt. Then played around with various options like:

xterm  -e  "export PS1=foo; $SHELL"

and so on ... But none seem to work. Can you please help?

$ xterm -version
XTerm(390)
$ bash --version
GNU bash, version 5.2.21(1)-release (x86_64-pc-linux-gnu)


Top Answer/Comment:

bash documentation quite clearly says:

If the -c option is present, then commands are read from the first non-option argument command_string.

So, bash executes the command export PS1=foo and terminates.

bash will not assign PS1 from the environment, so there is no point in exporting it.

What you can do is using some environment variable to set PS1. Like

$ tail -n 3 ~/.bashrc
if [ -n "$MY_BASH_PROMPT" ]; then
  PS1="$MY_BASH_PROMPT"
fi
$ 

and

$ xterm -e "export MY_BASH_PROMPT='PROMPT1> '; $SHELL"

PROMPT1

xterm -e "export MY_BASH_PROMPT='PROMPT2> '; $SHELL"

PROMPT2

상단 광고의 [X] 버튼을 누르면 내용이 보입니다