当我以 root 身份登录时:
ubuntu login: root
Password:
Last login: Tue Apr 7 17:31:14 CDT 2020 on ttyS0
Welcome to Ubuntu 19.04 (GNU/Linux 5.0.0-38-generic x86_64)
我的 /root/.bashrc (因此 /root/.bash_aliases)没有运行。这是正常的吗?我怎样才能解决这个问题?
更多信息:
# getent passwd| grep root
root:x:0:0:root:/root:/bin/bash
我的 /root/.profile 是正常的:
# cat /root/.profile
# ~/.profile: executed by Bourne-compatible login shells.
if [ "$BASH" ]; then
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
fi
mesg n || true
$BASH 设置正确:
# echo $BASH
/bin/bash
而/root/.bashrc也是正常的。这是一个片段:
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
如果我从命令行执行“. ~/.bashrc”,它会按预期工作。
如果存在~/.bash_profile
或~/.bash_login
存在,bash 将运行它而不是~/.profile
. 某些软件安装程序会将他们的安装步骤(通常)添加到 中~/.bash_profile
,因此即使您将其删除(并将其内容合并到 中~/.profile
),稍后也可能会重新创建。
理想情况下,我建议将所有 bash 特定的东西(即 sourcing ~/.bashrc
)移到 中~/.bash_profile
,让它也获取 generic ~/.profile
,只留下mesg
泛型中的~/.profile
(所以如果你在不同的shell 中开始它就会工作)
所以这就是我要输入的内容~/.profile
:
# cat /root/.profile
# ~/.profile: executed by Bourne-compatible login shells.
mesg n || true
并且~/.bash_profile
(请注意,它不必测试$BASH
,因为它已经在特定于 bash 的文件中):
# ~/.bash_profile: executed by bash login shells.
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# If the generic profile exists, source that as well.
if [ -f ~/.profile ]; then
. ~/. profile
fi
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句