Changing bash prompt in new bash

When I create a new bash process, the default request is very simple. I know I can change .bashrc etc. to change this, but is there any way to pass the prompt using the bash command?

thank!

+3
source share
3 answers

The request is determined by the environment variables PS1, PS2, PS3, and PS4. So, for example, the following will launch a new bash with the request set to "foo:":

PS1="foo: " bash --norc

--norcrequired to suppress the processing of initialization files that would override the variable PS1.

+6
source

- bash ; ; , ~/.bashrc, , , , ~/.bashrc ( ..) - PS1,

( , --init-file / --rcfile):

bash --rcfile <(cat ~/.bashrc ; echo 'PS1="\[\033[0;33m\]\u@HELLO:\W\$\[\033[00m\] "')

, / + <() bash; , stdout , /dev/fd/<n>. , ~/.bashrc; set PS1 ( ) - /dev/fd/<n>; bash /dev/fd/<n> rcfile.

:

user@pc:tmp$ TESTVAR="testing" bash --rcfile <(cat ~/.bashrc ; echo 'PS1="\[\033[0;33m\]\u@HELLO:\W\$\[\033[00m\] "')
user@HELLO:tmp$ test-alias-tab-completion ^C
user@HELLO:tmp$ echo $TESTVAR 
testing
user@HELLO:tmp$ exit
exit
user@pc:tmp$ 
+3

You can set the environment variable and then use this environment variable at the prompt in .bashrc.

0
source

All Articles