/etc/profile ~/.bash_profile ~/.bashrc /etc/bashrc文件调用顺序解析
来源:互联网 发布:广西干部网络培训 编辑:程序博客网 时间:2024/06/05 17:10
问题:
今天在安装pyenv的时候碰到了这么个问题:
WARNING: seems you still have not added 'pyenv' to the load path.
# Load pyenv automatically by adding
# the following to ~/.bash_profile:
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
大概意思就是说,pyenv这个二进制还没有加入加载路径,从它给出的补救方法可以看出,我们要对PATH进行适当的修改,并且运行后面两个eval里面的命令
于是按照所说的去做,并不其作用。
谷歌了一下~/.bash_profile这个文件,发现了网上有一些关于如题所示四个文件的调用顺序,然后发现这些文章讲的并不是很清晰:有个问题会在login shell调用,有的会在新建bash shell时调用,有的又会在某种情况下调用。因为对这些东西没有清晰的概念(虽然有一定的了解),所以想做个实验证明下他们的调用顺序问题。
他们的调用顺序应是如下面所是:
/etc/profile->~/.bash_profile->~/.bashrc->/etc/bashrc
(这里面后两个箭头是在判断该文件存在了才会去调用)、
1,首先我在四个文件当中分别插入“echo 文件名”这样的语句,其中文件名分别对应着四个文件的完整路径。在terminal中输入bash,输出/home/laozhikun/.bashrc和/etc/bashrc,其他两个文件没有被调用。
问题:/etc/profile和~/.bash_profile什么时候被调用?
2,查找资料,发现对/etc/profile文件的修改只有在系统重启后才会生效,于是重启动
3,重启动后,重新打开terminal,仍然只输出/home/laozhikun/.bashrc和/etc/bashrc。查找资料,发现/etc/profile面对的是全局,很有可能它的输出不是在某个tty里面输出。于是在/etc/profile里面加上一句“touch /tmp/aaaa”
4,重新启动,立即在命令行打开/tmp,可见aaaa,记录修改时间,等两分钟,再重新启动,再次查找/tmp/aaaa,可见aaaa修改时间改变。过两分钟再次打开terminal,可见aaaa时间戳未改变,可知/etc/profile的调用是在开机的时候调用的
5,受/etc/profile文件启发,对~/.bash_profile进行了相似的修改->加上"touch /tmp/bbbb",并且重启
6,可见/tmp出现bbbb文件,记录时间戳,等两分钟,再次重启动,可见bbbb时间戳改变,过两分钟打开terminal,可见bbbb时间戳为改变,可见~/.bash_profile的调用是在开机的时候调用的
7,那么/etc/profile和~/.bash_profile的调用顺序是什么,通过man ls得到ls的一个参数--full-time,它能够准确现实文件被touch的时间戳。重启电脑,通过观察aaaa和bbbb的精确时间戳,可以发现aaaa的touch时间比bbbb的touch时间早,所以/etc/profile文件应比~/.bash_profile调用顺序要早
8,受此启发,对~/.bashrc和/etc/bashrc分别进行了添加“touch cccc”和添加“touch dddd”的修改,并且重新启动
9,开机之后不使用terminal查看时间戳,因为开启shell会调用~/.bashrc和etc/bashrc,我们使用Fedora自带的文件管理其进行查看,并且将文件排序方式设定为按照修改时间排序,可见修改时间为aaaa<bbbb<cccc<dddd,可见调用顺序为/etc/profile->~/.bash_profile->~/.bashrc->/etc/bashrc
10,启动shell(terminal),可cccc和dddd在文件管理器中的顺序被移到了最后,而另外一个本来在cccc和dddd之后的临时文件被挤到了倒数第三,此时cccc<dddd,可见打开terminal只调用~/.bashrc和/etc/bashrc,并且调用顺序为~/.bashrc->/etc/bashrc
11,踪上,调用顺序为/etc/profile->~/.bash_profile->~/.bashrc->/etc/bashrc,其中前两个只在登陆系统调用,后面两个在登陆系统和打开新的shell的时候都调用
12,画图如下:
13,回归到遇到的问题,pyenv给出的补救方法必须在重启后才能生效,如果想不重启而生效,可以在~/.bashrc里面添加那段补救命令,然后运行bash,而不是加在~/.bash_profile中
- /etc/profile ~/.bash_profile ~/.bashrc /etc/bashrc文件调用顺序解析
- /etc/profile、/etc/bashrc、~/.bash_profile、~/.bashrc 四文件的区别
- /etc/profile、/etc/bashrc、~/.bash_profile、~/.bashrc
- /etc/profile、/etc/bashrc、~/.bash_profile、~/.bashrc
- /etc/profile、/etc/bashrc、~/.bash_profile、~/.bashrc 比较
- /etc/profile /etc/bashrc ~/.bash_profile ~/.bashrc 区别
- /etc/profile、/etc/bashrc、~/.bash_profile、~/.bashrc
- /etc/profile、/etc/bashrc、~/.bash_profile、~/.bashrc
- /etc/profile、/etc/bashrc、~/.bash_profile、~/.bashrc
- /etc/profile,/etc/bashrc,~/.bash_profile,~/.bashrc
- /etc/profile、/etc/bashrc、~/.bash_profile、~/.bashrc
- Linux /etc/profile,~/.bash_profile,~/.bashrc,/etc/bashrc
- /etc/profile、/etc/bashrc、~/.bash_profile、~/.bashrc
- /etc/profile、~/.bashrc、/etc/bashrc、~/.bash_profile、 ~/.bash_login、 ~/.profile、/etc/environment
- /etc/rc.d/rc.local 与 /etc/profile .bash_profile .bashrc 文件执行顺序
- .bash_profile vs .bashrc && /etc/profile vs /etc/bashrc
- 浅析linux 下的/etc/profile、/etc/bashrc、~/.bash_profile、~/.bashrc
- /etc/profile、/etc/bashrc、~/.bash_profile、~/.bashrc 的区别
- 2015半年总结,我要实现的个人目标
- LabWindows/CVI 下载
- Android---57---传感器
- 如何做移动O2O产品的运营推广
- Time Date DateTime的继承与派生及运算符重载
- /etc/profile ~/.bash_profile ~/.bashrc /etc/bashrc文件调用顺序解析
- Eclipse-jsp
- 用一个异质链表(多态性)保存学生数据
- 指令集
- Andorid之SlideMenuView
- 为Java程序员编写的Scala的入门教程
- 猫猫学iOS之小知识iOS启动动画_Launch Screen的运用
- 直方图均衡化
- 算法导论31(数论算法)