您的位置:首页 > 运维架构 > Shell

每次登录都要执行source .basharc,否则ll等命令失效

2017-06-20 10:18 162 查看
问题:

有时候修改了.bashrc文件后,每次登录都得重新执行source .bashrc才行。

或者用其他软件类似mobaXterm通过ssh终端连接时,没有ll等命令,也要执行source .bashrc才可以。

解决方法:

1)每次登录都执行一下,这是可以的

2)在当前用户目录,增加一个.profile文件,增加以下内容

# if running bash
if [ -n "$BASH_VERSION" ]; then
# include .bashrc if it exists
if [ -f "$HOME/.bashrc" ]; then
. "$HOME/.bashrc"
fi
fi

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
PATH="$HOME/bin:$PATH"
fi


基本思路:

1)登录时基本配置文件读取流程如下:

execute /etc/profile
IF ~/.bash_profile exists THEN
execute ~/.bash_profile
ELSE
IF ~/.bash_login exist THEN
execute ~/.bash_login
ELSE
IF ~/.profile exist THEN
execute ~/.profile
END IF
END IF
END IF
所以,能看出读取了/etc/.profile后回去找用户目录下的.profile,所以我们在用户目录下增加这个文件,

里面代码让系统帮我们读取用户下的.bashrc,这样我们就不用每次登陆后自己去执行了。

想去了解更多的童鞋,可以去看看面的链接,我也是借鉴别人的,互相学习。

参考:

1)http://www.ithao123.cn/content-2565999.html

2)https://reyesyang.info/articles/26-how-to-initialize-a-new-shell-in-unix-like-os
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  source .barsh ll失效 ssh