解决每次打开终端都需要source .bashrc文件的问题
太长不看版本:解决方法:cdvim .bash_profile输入下面内容后 :wq 保存并退出# .bash_profileif [ -f ~/.bashrc ]; then. ~/.bashrcfi机理这个问题就在于,系统
太长不看版本:
解决方法:
cd
vim .bash_profile
输入下面内容后 :wq 保存并退出
# .bash_profile
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
机理
这个问题就在于,系统没有自动的执行 .bashrc 这个文件,导致我们每次登陆时候都需要source 这个文件。如果不source 这个文件最大的影响就是文件夹和 文件我们看不出来,都是白色的。source 之后呢,文件夹就会变成蓝色的,可执行文件就会变成绿色的,这样更方便我们工作。
source 前:
source 后:
1.Linux 启动时读取配置文件的顺序
在刚登录Linux时,首先启动/etc/profile
文件,然后再启动用户目录下的 ~/.bash_profile
、~/.bash_login
或 ~/.profile
文件中的其中一个。
具体执行的顺序为:~/.bash_profile
、~/.bash_login
、 ~/.profile
如果 ~/.bash_profile
文件存在的话,一般还会执行 ~/.bashrc
文件。
因为在~/.bash_profile
文件中会有以下内容:
# .bash_profile
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
~/.bashrc中一般有以下内容,这是执行/etc/下总的bashrc 文件,全局环境变量。
1 # .bashrc
2
3 # Source global definitions
4 if [ -f /etc/bashrc ]; then
5 . /etc/bashrc
6 fi
综上,执行顺序可以总结为:
/etc/profile
→ (~/.bash_profile
| ~/.bash_login
| ~/.profile
)→~/.bashrc
→/etc/bashrc
所以,要自动的执行~/.bashrc
,只需要将以下代码,放到~/.bash_profile
文件里就好了,如果没有这个文件就新建一个。
# .bash_profile
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
更多推荐
所有评论(0)