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

来源:互联网 发布:可以看央视的网络电视 编辑:程序博客网 时间:2024/05/16 02:21

问题:

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

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


解决方法:

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

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

# if running bashif [ -n "$BASH_VERSION" ]; then    # include .bashrc if it exists    if [ -f "$HOME/.bashrc" ]; then    . "$HOME/.bashrc"    fifi# set PATH so it includes user's private bin if it existsif [ -d "$HOME/bin" ] ; then    PATH="$HOME/bin:$PATH"fi

基本思路:

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

execute /etc/profileIF ~/.bash_profile exists THEN    execute ~/.bash_profileELSE    IF ~/.bash_login exist THEN        execute ~/.bash_login    ELSE        IF ~/.profile exist THEN            execute ~/.profile        END IF    END IFEND 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

阅读全文
0 0
原创粉丝点击