<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></title> 
<link>http://www.jackxiang.com/index.php</link> 
<description><![CDATA[赢在IT，Playin' with IT,Focus on Killer Application,Marketing Meets Technology.]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[向东博客 专注WEB应用 构架之美 --- 构架之美，在于尽态极妍 | 应用之美，在于药到病除]]></copyright>
<item>
<link>http://www.jackxiang.com/post//</link>
<title><![CDATA[[实践OK]Linux下登录后执行系统的shell顺序，浅析linux 下的/etc/profile、/etc/bashrc、~/.bash_profile、~/.bashrc 文件，登录Linux时/etc/profile、~/.bash_profile等几个文件的执行过程。]]></title> 
<author>jack &lt;xdy108@126.com&gt;</author>
<category><![CDATA[Unix/LinuxC技术]]></category>
<pubDate>Mon, 12 Oct 2015 07:34:55 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//</guid> 
<description>
<![CDATA[ 
	背景：这个linux用户登录进行相关环境变量的设置和下面这些全局和用户之前的关系，值得大致有一个理解，特别是环境变量，有一些程序运行的环镜参数息息相关，还有类似如对secureCRT标签的设置（为什么就登录失效没有触发呢，直接运行又OK等问题有疑惑，排查问题困难），/etc/bashrc /etc/sysconfig/bash-prompt-xterm 里设置secureCRT标签，怎么登录就没有变呢，而是直接运行source /etc/bashrc即可生效（运行source XXX之前，先运行bash，即：1）bash 2）source XXX）：/etc/bashrc&nbsp;&nbsp;里面包含/etc/sysconfig/bash-prompt-xterm 文件就能设置了呢，/etc/bashrc: 为每一个运行bash shell的用户执行此文件.当bash shell被打开时,该文件被读取。此中必然有蹊跷，设置secureCRT 的标签见：http://jackxiang.com/post/6773/ ，是阿里云给修改了这个：/etc/bashrc 里加入新变量：if [ -z &quot;$PROMPT_COMMAND&quot; ]; then ，它不为空，没有运行这个/etc/sysconfig/bash-prompt-xterm 文件,解决办法就是：PROMPT_COMMAND=&quot;&quot;;强制清空得了，重新运行source&nbsp;&nbsp;/etc/bashrc就Ok了 。<br/><br/>执行顺序如下：<br/>/etc/bashrc ==&gt;（PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm）=》 /etc/profile/etc/profile.d/ [2.for i in /etc/profile.d/*.sh ; do]&nbsp;&nbsp;==&gt;.bash_profile =（包含:. ~/.bashrc）=. ~/.bashrc。（首先启动 /etc/profile 文件，然后再启动用户目录下的 ~/.bash_profile），摘自：http://blog.51cto.com/xoyabc/1658135<br/><br/>/etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行.<br/>并从/etc/profile.d目录的配置文件中搜集shell的设置.<br/><br/>/etc/bashrc:为每一个运行bash shell的用户执行此文件.当bash shell被打开时,该文件被读取.<br/><br/>~/.bash_profile:每个用户都可使用该文件输入专用于自己使用的shell信息,当用户登录时,该<br/>文件仅仅执行一次!默认情况下,他设置一些环境变量,执行用户的.bashrc文件.<br/><br/>~/.bashrc:该文件包含专用于你的bash shell的bash信息,当登录时以及每次打开新的shell时,该<br/>该文件被读取.<br/><br/>~/.bash_logout:当每次退出系统(退出bash shell)时,执行该文件.<br/><br/>另外,/etc/profile中设定的变量(全局)的可以作用于任何用户,而~/.bashrc等中设定的变量(局部)只能继承/etc/profile中的变量,他们是&quot;父子&quot;关系.<br/><br/>~/.bash_profile 是交互式、login 方式进入 bash 运行的<br/><br/>~/.bashrc 是交互式 non-login 方式进入 bash 运行的<br/><br/>通常二者设置大致相同，所以通常前者会调用后者。<br/><br/> <br/><br/>bash的几个初始化文件 - [Ubuntu]<br/><br/> <br/><br/>（1）/etc/profile<br/>全局（公有）配置，不管是哪个用户，登录时都会读取该文件。<br/><br/>（2）/ect/bashrc<br/>Ubuntu没有此文件，与之对应的是/ect/bash.bashrc <br/>它也是全局（公有）的<br/>bash执行时，不管是何种方式，都会读取此文件。<br/><br/>（3）~/.profile<br/>若bash是以login方式执行时，读取~/.bash_profile，若它不存在，则读取~/.bash_login，若前两者不存在，读取~/.profile。<br/>另外，图形模式登录时，此文件将被读取，即使存在~/.bash_profile和~/.bash_login。<br/><br/>（4）~/.bash_login<br/>若bash是以login方式执行时，读取~/.bash_profile，若它不存在，则读取~/.bash_login，若前两者不存在，读取~/.profile。<br/><br/>（5）~/.bash_profile<br/>Unbutu默认没有此文件，可新建。<br/>只有bash是以login形式执行时，才会读取此文件。通常该配置文件还会配置成去读取~/.bashrc。<br/><br/>（6）~/.bashrc<br/>当bash是以non-login形式执行时，读取此文件。若是以login形式执行，则不会读取此文件。<br/><br/>（7）~/.bash_logout<br/>注销时，且是longin形式，此文件才会读取。也就是说，在文本模式注销时，此文件会被读取，图形模式注销时，此文件不会被读取。<br/><br/>下面是在本机的几个例子：<br/>1. 图形模式登录时，顺序读取：/etc/profile和~/.profile<br/>2. 图形模式登录后，打开终端时，顺序读取：/etc/bash.bashrc和~/.bashrc<br/>3. 文本模式登录时，顺序读取：/etc/bash.bashrc，/etc/profile和~/.bash_profile<br/>4. 从其它用户su到该用户，则分两种情况：<br/>&nbsp;&nbsp;&nbsp;&nbsp;（1）如果带-l参数（或-参数，--login参数），如：su -l username，则bash是lonin的，它将顺序读取以下配置文件：/etc/bash.bashrc，/etc/profile和~/.bash_profile。<br/>&nbsp;&nbsp;&nbsp;&nbsp;（2）如果没有带-l参数，则bash是non-login的，它将顺序读取：/etc/bash.bashrc和~/.bashrc<br/>5. 注销时，或退出su登录的用户，如果是longin方式，那么bash会读取：~/.bash_logout<br/>6. 执行自定义的shell文件时，若使用“bash -l a.sh”的方式，则bash会读取行：/etc/profile和~/.bash_profile，若使用其它方式，如：bash a.sh， ./a.sh，sh a.sh（这个不属于bash shell），则不会读取上面的任何文件。<br/>7. 上面的例子凡是读取到~/.bash_profile的，若该文件不存在，则读取~/.bash_login，若前两者不存在，读取~/.profile。<br/><br/> <br/><br/> <br/><br/> <br/><br/>linux中profile与bashrc的区别<br/>Ubuntu 的相关目录下<br/>/ect/ /root /home/myuser <br/>profile .profile .profile <br/>bash.bashrc .bashrc .bashrc<br/>profile.d<br/><br/>Fedora的相关目录<br/>/ect/ /root /home/myuser <br/>profile 　　　　 profile <br/>bashrc 　　.bashrc bashrc<br/>profile.d 　　　　　　　　　　　　　　　　　　　　profile.d<br/><br/>说明：myuser　是你添加创建的用户<br/>在网上找了半天也不能包括所有的，所以只能比较个大概。<br/><br/> <br/><br/>bashrc与profile的区别<br/><br/>要搞清bashrc与profile的区别，首先要弄明白什么是交互式shell和非交互式shell，什么是login shell 和non-login shell。<br/><br/>交互式模式就是shell等待你的输入，并且执行你提交的命令。这种模式被称作交互式是因为shell与用户进行交互。这种模式也是大多数用户非常熟悉的：登录、执行一些命令、签退。当你签退后，shell也终止了。 shell也可以运行在另外一种模式：非交互式模式。在这种模式下，shell不与你进行交互，而是读取存放在文件中的命令,并且执行它们。当它读到文件的结尾，shell也就终止了。<br/><br/>bashrc与profile都用于保存用户的环境信息，bashrc用于交互式non-loginshell，而profile用于交互式log<br/><br/><br/>来自：http://blog.renren.com/share/224354794/8635033605<br/>========================登录Linux时/etc/profile、~/.bash_profile等几个文件的执行过程&nbsp;&nbsp;========================<br/>关于登录linux时，/etc/profile、~/.bash_profile等几个文件的执行过程。 在登录Linux时要执行文件的过程如下： 在刚登录Linux时，首先启动 /etc/profile 文件，然后再启动用户目录下的 ~/.bash_profile、 ~/.bash_login或 ~/.profile文件中的其中一个，执行的顺序为：~/.bash_profile、 ~/.bash_login、 ~/.profile。如果 ~/.bash_profile文件存在的话，一般还会执行 ~<br/>关于登录linux时，/etc/profile、~/.bash_profile等几个文件的执行过程。<br/><br/>在登录Linux时要执行文件的过程如下：<br/><br/>在刚登录Linux时，首先启动 /etc/profile 文件，然后再启动用户目录下的 ~/.bash_profile、 ~/.bash_login或 ~/.profile文件中的其中一个，执行的顺序为：~/.bash_profile、 ~/.bash_login、 ~/.profile。如果 ~/.bash_profile文件存在的话，一般还会执行 ~/.bashrc文件。因为在 ~/.bash_profile文件中一般会有下面的代码：<br/><br/>if [ -f ~/.bashrc ] ; then<br/><br/>. ./bashrc<br/><br/>fi<br/><br/>~/.bashrc中，一般还会有以下代码：<br/><br/>if [ -f /etc/bashrc ] ; then<br/><br/>. /bashrc<br/><br/>fi<br/><br/>所以，~/.bashrc会调用 /etc/bashrc文件。最后，在退出shell时，还会执行 ~/.bash_logout文件。<br/><br/>执行顺序为：/etc/profile -&gt; (~/.bash_profile &#124; ~/.bash_login &#124; ~/.profile) -&gt; ~/.bashrc -&gt; /etc/bashrc -&gt; ~/.bash_logout<br/><br/>关于各个文件的作用域，在网上找到了以下说明：<br/><br/>（1）/etc/profile： 此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行. 并从/etc/profile.d目录的配置文件中搜集shell的设置。<br/><br/>（2）/etc/bashrc: 为每一个运行bash shell的用户执行此文件.当bash shell被打开时,该文件被读取。<br/><br/>（3）~/.bash_profile: 每个用户都可使用该文件输入专用于自己使用的shell信息,当用户登录时,该文件仅仅执行一次!默认情况下,他设置一些环境变量,执行用户的.bashrc文件。<br/><br/>（4）~/.bashrc: 该文件包含专用于你的bash shell的bash信息,当登录时以及每次打开新的shell时,该该文件被读取。<br/><br/>（5）~/.bash_logout:当每次退出系统(退出bash shell)时,执行该文件. 另外,/etc/profile中设定的变量(全局)的可以作用于任何用户,而~/.bashrc等中设定的变量(局部)只能继承 /etc/profile中的变量,他们是&quot;父子&quot;关系。<br/><br/>（6）~/.bash_profile 是交互式、login 方式进入 bash 运行的~/.bashrc 是交互式 non-login 方式进入 bash 运行的通常二者设置大致相同，所以通常前者会调用后者。<br/><br/>在这里开始书写日记、心情 …<br/><br/>来自：http://blog.163.com/jianweicheng@126/blog/static/356732022008228559399/
]]>
</description>
</item><item>
<link>http://www.jackxiang.com/post//#blogcomment</link>
<title><![CDATA[[评论] [实践OK]Linux下登录后执行系统的shell顺序，浅析linux 下的/etc/profile、/etc/bashrc、~/.bash_profile、~/.bashrc 文件，登录Linux时/etc/profile、~/.bash_profile等几个文件的执行过程。]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.jackxiang.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>