首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >尽管在PS1中设置了.bashrc,但仍无法获得彩色提示

尽管在PS1中设置了.bashrc,但仍无法获得彩色提示
EN

Ask Ubuntu用户
提问于 2018-02-13 17:19:16
回答 1查看 1.4K关注 0票数 1

我通过ssh登录的一台机器没有给我一个彩色提示,尽管它是通过.bashrc设置的。所讨论的.bashrc部分是

代码语言:javascript
复制
# 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。如果我用

代码语言:javascript
复制
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。我怀疑同样的根本原因,但我不知道该去哪里找。

EN

回答 1

Ask Ubuntu用户

回答已采纳

发布于 2018-02-13 19:03:23

在使用ssh时,您将获得登录shell。

来自~/.profile

代码语言:javascript
复制
# ~/.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文件-

代码语言:javascript
复制
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
        . "$HOME/.bashrc"
    fi
fi
票数 2
EN
页面原文内容由Ask Ubuntu提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://askubuntu.com/questions/1005869

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档