我通过ssh登录的一台机器没有给我一个彩色提示,尽管它是通过.bashrc设置的。所讨论的.bashrc部分是
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color|*-256color) color_prompt=yes;;
esac
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi
if [ "$color_prompt" = yes ]; then
if [ $(id -u) -eq 0 ];
then # you are root, make the prompt red
PS1='${debian_chroot:+($debian_chroot)}\[\e[00;33m\]\u\[\e[00m\]@\[\e[00;34m\]\h\[\e[00m\]:\[\e[00;36m\]\w\[\e[00m\]\e[01;31m#\e[00m '
else
PS1='${debian_chroot:+($debian_chroot)}\[\e[00;32m\]\u\[\e[00m\]@\[\e[00;34m\]\h\[\e[00m\]:\[\e[00;36m\]\w\[\e[00m\]$ '
fi
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt我把它用在其他几台机器上,得到了预期的结果。
我不知道为什么这台电脑不使用这个.bashrc。如果我用
export PS1='${debian_chroot:+($debian_chroot)}\[\e[00;32m\]\u\[\e[00m\]@\[\e[00;34m\]\h\[\e[00m\]:\[\e[00;36m\]\w\[\e[00m\]$ '(上面的行),我的提示符得到了所需的格式。/etc/bash.bashrc存在,/etc/profile也存在,在我看来都很好。
另外,如果我在这台计算机上使用ssh,xterm标题就不会被设置。通常,它会被设置为这台机器的user@host。我怀疑同样的根本原因,但我不知道该去哪里找。
发布于 2018-02-13 19:03:23
在使用ssh时,您将获得登录shell。
来自~/.profile
# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login exists.因此,请确保此文件存在于您要登录的用户的主目录中。如果不存在,则创建该文件并通过键入以下命令强制它读取~/.bashrc文件-
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fihttps://askubuntu.com/questions/1005869
复制相似问题