假设我正在重新安装Debian、Jessie (或Wheezy)。作为普通用户,我在/etc/bash.bashrc文件中定义了提示符,最终被/home/foobar/.bashrc中的提示覆盖
好吧,酷,我有这样的东西:foobar@myserver:~$,我正在试着理解下面的代码:
# 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如您所见,PS1变量(=提示符)似乎又被高估了(因为我在xterm中)。但是我不明白为什么我们在这条线的末尾有另一个$PS1!
为了得到这一点,我在这一行中添加了3个字母a b c:
PS1="a\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]b$PS1 c"现在,我有一个奇怪的提示:
abfoobar@myserver:~$ c因此,似乎几乎整条线都没有使用,所有的东西都在虚张声势之间。
PuTTY运行这个xterm;在ubuntu中,这一行与PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'完全不同发布于 2017-05-04 09:03:07
\[ \]之间的部分似乎是由终端处理的转义序列:ESC ],它命名为OSC,用于下面的链接X项转义序列中的操作系统命令。
OSC Ps ; Pt ST
Set Text Parameters. For colors and font, if Pt is a "?", the
control sequence elicits a response which consists of the con-
trol sequence which would set the corresponding value. The
dtterm control sequences allow you to determine the icon name
and window title.
Ps = 0 -> Change Icon Name and Window Title to Pt.它将更改xterm窗口标题。
由于窗口标题包含当前工作目录设置,提示允许在cd命令后更改目录时更新标题。
https://stackoverflow.com/questions/43777479
复制相似问题