登录 Shell 与非登录 Shell <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

首先给大家介绍一个文件, startup 文件 , 登录 shell 时要执行的文件,在以后登录时初始化用户登录后的环境。在 linux 中,若果默认 Shell bash shell 时,默认有多个 startup 文件 , 不去读取的方式和次序也并不相同。

大家对登录 Shell 与非登录 Shell 的概念可能还比价模糊,举个例子,当你登陆系统时,系统提示输入用户名,密码,此时用的 shell 就是登录 shell ; 在任务自动化执行时,脚本运行时所关联的 shell 就是费登录 shell , 此时不需要用户登录。登录 Shell 与非登录 Shell 所用的文件和环境不同

/ ect/profile( 每个用户登录时读取此文件,这里定义了用户的环境变量 )     /etc/profile.d/* 登录后此目录下的所有文件都会执行,这就是startup文件。
总结读取文件过程:shell璋冪敤鏂囦欢杩囩▼

登录时 Shell 先读取 / ect/profile ,在读取 ~/.bash_profile ,在读取 /etc/profile.d/* 下的所有文件,在读取家目录下的 ~/.bashrc ~/.bashrc 在调用 / etc/bashrc 文件;非登录时 Shell 先读取 ~/.bashrc ~/.bashrc 在调用 / etc/bashrc 文件,然后在读取 /etc/profile.d/* 下的所有文件

 
其中 profile 用来定义环境变量, bashrc 定义本地变量和别名等。因此在 . bashrc 文件中定义的别名永久有效。 但需用 source . bashrc 重新读取该文件才生效。

 

~/.bash_profile   ~/.bashrc

非登录时 Shell 读取   /etc/bashrc ,其实登录时 shell 也读取此文件,只是读取 的次序不一样