标题的PS1如何不覆盖提示的PS1

How the PS1 of the title doesn't overwrite the PS1 of the prompt

我注意到在~/.bashrc中有两组PS1:

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[3[01;32m\]\u@\h\[3[00m\]:\[3[01;34m\]\w\[3[00m\]$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$'
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h:\w\a\]$PS1"
    ;;
*)
    ;;
esac

第一个检查 $color_prompt,是否为真,并决定 提示的文本
第二个检查 $TERM 并决定 title.

但它们都更改了 相同的 环境变量,因此当终端启动并“看到” PS1 设置为 文本的提示,怎么还可以设置标题呢? ~/.bashrc 是否被加载了两次?

第一个条件根据是否启用$color_prompt设置$PS1。第二个分配通过将 $PS1 设置为表达式 来扩展它,该表达式包含 $PS1

的先前值
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h:\w\a\]$PS1"
# Here ---------------------------------------------------^