When I create an new bash process, the prompt defaults to a very simple one. I know I can edit .bashrc etc to change this, but is there a way of passing the prompt with the bash command?
thanks!
The prompt is defined by the PS1, PS2, PS3 and PS4 environment variables. So, e.g. the following will start a new bash with the prompt set to "foo: ":
PS1="foo: " bash --norc
The --norc
is required to suppress processing of the initialization files, which would override the PS1
variable.
I have the same problem - I'd like to startup a temporary bash from the command line; and while most other environment variables remain; those that are sourced from ~/.bashrc
are kind of difficult to override - especially if you, like me, would actually like to keep the ~/.bashrc
you already have (and aliases inside, etc.) - save for the PS1
prompt.
Here is something that works for me (note that --init-file
is a synonym/alias for --rcfile
):
bash --rcfile <(cat ~/.bashrc ; echo 'PS1="\[\033[0;33m\]\u@HELLO:\W\$\[\033[00m\] "')
Basically, the bracket/less-than + parenthesis idiom <()
starts up bash
process substitution; everything echoed to stdout inside the parenthesis will end up in a temporary file, /dev/fd/<n>
. So we first cat the contents of out ~/.bashrc
; then we simply add a PS1
set command at end, (which effectively overrides) - this ends up in /dev/fd/<n>
; and bash
then uses /dev/fd/<n>
for the new rcfile
.
This is how it behaves:
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$
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With