我注意到当我 ssh 到服务器然后 su 到 root 用户时,我没有在 bash 中获得颜色。在这种特定情况下,当我说“不要在 bash 中获取颜色”时,我指的是使用 vim 编辑文件。现在,如果我在登录后 sudo 会得到颜色,所以那里没有问题。如果我 su 到 root 和 source /root/.bash_profile 那么我以 root 身份获得颜色。但是我不想在每次 su 到 root 时都必须获取 .bash_profile 文件。这是我的 /root/.bashrc 和 /root/.bash_profile 文件的内容。执行 su 时我该怎么做才能获得颜色?
# .bashrc
# User specific aliases and functions
# You may uncomment the following lines if you want `ls' to be colorized:
export LS_OPTIONS='--color=auto'
eval "`dircolors`"
alias ls='ls $LS_OPTIONS'
alias ll='ls $LS_OPTIONS -l'
alias l='ls $LS_OPTIONS -lA'
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
Run Code Online (Sandbox Code Playgroud)
==============================================
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
alias vi='/usr/bin/vim'
alias grep='/bin/grep --color'
export EDITOR=/usr/bin/vim
# HISTSIZE = number of lines in memory while session is ongoing
# HISTFILESIZE = maximum number of lines in the history file on disk
export HISTSIZE=3000
export HISTFILESIZE=5000
export HISTFILE=/root/history/.bash_hist-$(who -m | awk '{print $1}')
Run Code Online (Sandbox Code Playgroud)