How to change bash prompt string in current bash session?
Does Debian really pick up a changed hostname if PS1
is re-exported, as the other answers suggest? If so, you can just refresh it like this:
export PS1="$PS1"
Don't know about debian, but on OS X Mountain Lion this will not have any effect. Neither will the explicit version suggested in other answers (which is exactly equivalent to the above).
Even if this works, the prompt must be reset separately in every running shell. In which case, why not just manually set it to the new hostname? Or just launch a new shell (as a subshell with bash
, or replace the running process with exec bash
)-- the hostname will be updated.
To automatically track hostname changes in all running shells, set your prompt like this in your .bashrc
:
export PS1='\u@$(hostname):\w\$ '
or in your case:
export PS1='${debian_chroot:+($debian_chroot)}\u@$(hostname):\w\$ '
I.e., replace \h
in your prompt with $(hostname)
, and make sure it's enclosed in single quotes. This will execute hostname
before every prompt it prints, but so what. It's not going to bring the computer to its knees.
The hostname does not get updated automatically in the prompt. You have to reexport the $PS1
variable:
export PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$'
This variable is already set in your .bashrc
or other BASH config file, as shown by lines #1 and #2 of your output. But once you modify the hostname, you need to reexport the variable with the command above if you want the new prompt to get updated.