在某些Linux机器上,开启screen后,当设置了tab的title(Ctrl+A,A)后,输入任意命令,tab title会被重置为机器名称。
之前在某厂实习的时候,也遇到了相同的问题,一直以为是screen配置的问题。
其实,这是bash的配置。
看~/.bashrc:
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
而在/etc/bashrc中,有以下几行:
# are we an interactive shell?
if [ "$PS1" ]; then
case $TERM in
xterm*)
if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm
else
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\007"'
fi
;;
screen)
if [ -e /etc/sysconfig/bash-prompt-screen ]; then
PROMPT_COMMAND=/etc/sysconfig/bash-prompt-screen
else
PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\033\\"'
fi
;;
*)
[ -e /etc/sysconfig/bash-prompt-default ] && PROMPT_COMMAND=/etc/sysconfig/bash-prompt-default
;;
esac
# Turn on checkwinsize
shopt -s checkwinsize
[ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\H \W]\\$ "
fi
不难发现,若检测当前为screen的时候,强制写入了shell的标题为机器名,而这个值的设定,与screen tab的title实际是冲突的,因此,我们只要把screen的这个switch注视掉,就好了。
如下:
# are we an interactive shell?
if [ "$PS1" ]; then
case $TERM in
xterm*)
if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm
else
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\007"'
fi
;;
#screen)
# if [ -e /etc/sysconfig/bash-prompt-screen ]; then
# PROMPT_COMMAND=/etc/sysconfig/bash-prompt-screen
# else
# PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\033\\"'
# fi
# ;;
*)
[ -e /etc/sysconfig/bash-prompt-default ] && PROMPT_COMMAND=/etc/sysconfig/bash-prompt-default
;;
esac
# Turn on checkwinsize
shopt -s checkwinsize
[ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\H \W]\\$ "
fi