Bash is a shell supported by major Linux distributions. When we landed bash, we didn't do anything, but we were able to invoke a variety of environment variables in bash. This is because a series of configuration files have been defined in the system and the rules for loading them. Below is an example of CentOS. Before that, we need to understand two concepts: the login shell and the Non-login shell. Obviously, the difference between the two is that login is not required, and the rules for loading configuration files for both shells are not the same.
Login Shell: In layman's words, when we log into the shell, we need to enter the complete login information, that is, the user name and password
non-login Shell: In contrast to the login shell, you do not need to enter the login information when logging into the shell. For example: On an existing bash, launch a new bash, and after landing X window, launch a bash. Both of these are not required to enter the login information.
Here we begin to learn about bash's configuration files:
/etc/profile: The system level or global setting. We generally do not recommend to modify this file. We can also get more information from the comments in this file (for example, how to customize the configuration). Such as:
/etc/inputrc: Handles keyboard mappings for specific situations, such as Bash hotkeys. /etc/profile will determine if there is a user-defined inputrc, if not set INPUTRC=/ETC/INPUTRC (note: see CentOS 6.5/etc/profile, has not loaded/etc/ INPUTRC's code. This needs to be done)
/etc/profile.d/*.sh: Some shell settings and user-defined configurations can be placed in this
/etc/sysconfig/i18n: Defines the language and encoding used by bash
~/.bash_profile, ~/.bash_login, ~/.profile: These three files are custom files that belong to the user. Then bash only reads one and ignores the other two. The rule is that the first one exists, ignoring the next two, and so on.
~/.BASHRC: This file will be loaded by ~/.bash_profile
You can open a specific profile to see what the specific configuration file loads and what environment variables are defined. By the end of these configuration files, the login shell and the Non-login shell load the configuration file rules.
The Non-login Shell's rules for loading configuration files are simple, it simply loads ~/.BASHRC. (If/ETC/BASHRC exists, then/ETC/BASHRC will also be loaded, as shown)
Login Shell The rules for loading profiles are a little more complicated, usable representations (solid lines represent the main process, dashed lines represent the invocation of the configuration file)
Rookie Learn Linux-bash configuration file