When you start the shell, it runs the startup file to initialize itself. Which file to run depends on how the shell interacts with a login shell or a non-landing shell (for example, through bash) or a non-interactive shell (to execute shell scripts). To execute the command in the startup file, the user must have Read permission, and the generic Linux distribution will place the corresponding command in some boot files.
1. Interactive login (login) shell
The interactive login shell refers to the shell that is used when the user logs on to the system (which can be specified by default, such as Bash--login). The login shell will look for several different startup files to handle the commands in it, and the bash shell processes the files in the following order:
/etc/profile:shell first executes the commands in/etc/profile. After setting this file, you can create a default feature for all bash users in the system (different versions of Linux will not have the same commands placed in this file).
~/.bash_profile, ~/.bash_login, ~/.profile: Then the shell looks up the files in turn and executes the commands in the first file it finds. You can place commands in these files to override the default settings in the/etc/profile file.
~/.bash_logout: When the user logs off, bash executes the command in the file ~/.bash_logout, which contains the cleanup commands that are executed when exiting the session, such as deleting temporary files, and so on.
2. Interactive non-login (non-login) shell
The interactive non-login shell refers to an interactive non-logon shell that launches a bash shell without waiting for a recording system (such as typing bash at the CLI prompt). The interactive non-logon shell does not execute the commands in the startup file mentioned earlier, but the interactive non-login shell inherits the shell variables set by these boot files from the login shell.
/ETC/BASHRC: Although not directly called through bash, many ~/.BASHRC files call/ETC/BASHRC. This setting allows the Superuser to establish default properties for the non-landing shell within the system.
~/.BASHRC: The interactive non-login shell executes the commands in the ~/.BASHRC file, and the login Shell's startup file (such as ~/.bash_profile) typically runs the file. In this way, both the login shell and the non-login shell can run commands in ~/.BASHRC.
3. Non-interactive shell
A non-interactive shell refers to a file that runs in shell script (that is, the. Sh end). In this mode, the shell does not interact with the user at runtime (unless the user is required to specify the run parameters at run time), but instead reads the commands stored in the file and executes them. When it reads the end of the file, the shell terminates. These shells inherit the shell variables set by these startup files from the time of landing.
Bash_env: The non-interactive shell looks for environment variable bash_env (or ENV when called as SH) and executes the command in the file named by the variable.
4. Test:
Set the following variables in ~/.bash_profile:
Lshell= "Login Shell would see this message"
Launch an interactive non-login shell and interactive login shell, respectively, to view the Lshell variables:
#注意: $ is not a command
$ bash$ echo $lshell $ exitexit$ bash--login$ echo $lshelllogin Shell would see this message$ exitlogout
It is visible that the Non-login shell is not read by the ~/.bash_profile,login shell and is consistent with the description above.
Reference:
http://baike.baidu.com/item/%E4%BA%A4%E4%BA%92%E5%BC%8F%E7%99%BB%E5%BD%95 (interactive login mode)
http://www.cnblogs.com/zengkefu/p/5492532.html (interactive login mode)
Http://www.cnblogs.com/zhaoyl/archive/2012/07/07/2580744.html (Interactive login method from this article)
http://blog.csdn.net/li19236/article/details/41486587 (interactive login mode)
Http://www.cnblogs.com/qcly/p/3273373.html (Interactive login method test transferred from this article)
Https://help.ubuntu.com/community/EnvironmentVariables (Ubuntu environment variable setting)
Http://www.cnblogs.com/liduanjun/p/3536993.html (configuration file description transferred from this article)
Http://www.cnblogs.com/xiehongfeng100/p/4969477.html (configuration file description)
Http://blog.chinaunix.net/uid-354915-id-3568853.html (configuration file description)
Http://www.cnblogs.com/mengyan/archive/2012/09/04/2669894.html (configuration file description)
Http://www.linuxidc.com/Linux/2015-01/111459.htm (configuration file description)
Http://www.cnblogs.com/yymn/p/5698623.html (configuration file description)
Http://blog.sina.com.cn/s/blog_8795b0970101f1f9.html (configuration file description)
Configuration file analysis in Linux environment variable settings (/ETC/PROFILE,~/.BASHRC, etc.) (RPM)