When logging on to Linux, start the/etc/profile file first, and then start ~ /. Bash_profile,
The file execution process when logging on to Linux is as follows:
When logging on to Linux, start the/etc/profile file first, and then start ~ /. Bash_profile ,~ /. Bash_login or ~ /One of the. profile files,
The execution sequence is :~ /. Bash_profile ,~ /. Bash_login ,~ /. Profile.
If ~ /. If the bash_profile file exists, it is generally executed ~ /. Bashrc file.
Because in ~ The/. bash_profile file usually contains the following code:
123 |
If [-f ~ /. Bashrc]; then ../bashrcfi |
~ /. Bashrc usually has the following code:
123 |
If [-f/etc/bashrc]; then./etc/bashrcfi |
So ,~ /. Bashrc calls the/etc/bashrc file. Finally, when you exit the shell, ~ /. Bash_logout file.
The execution sequence is:/etc/profile-> (~ /. Bash_profile | ~ /. Bash_login | ~ /. Profile)-> ~ /. Bashrc->/etc/bashrc-> ~ /. Bash_logout
The scope of each file is described as follows:
(1)/etc/profile: This file sets the environment information for each user in the system. when the user logs on for the first time, this file is executed. and from/etc/profile. d Directory configuration file to collect shell settings.
(2)/etc/bashrc: execute this file for every user running bash shell. when the bash shell is opened, the file is read (that is, bashrc is executed every time a terminal is opened ).
(3 )~ /. Bash_profile: each user can use this file to input the shell Information dedicated to his/her use. when a user logs on, this file is executed only once. By default, some environment variables are set to execute the user's. bashrc file.
(4 )~ /. Bashrc: This file contains bash information dedicated to your bash shell. This file is read when you log on and every time you open a new shell.
(5 )~ /. Bash_logout: execute this file every time you exit the system (exit bash shell). In addition, the variable (global) set in/etc/profile can act on any user, and ~ The variables (local) set in/. bashrc can only inherit the variables in/etc/profile. they are "parent-child" relationships.
(6 )~ /. Bash_profile: enters bash for interactive and login running ~ /. Bashrc is the interactive non-login mode that enters bash. Generally, the two settings are roughly the same, so the former usually calls the latter.
Use of environment variable setting files such as/etc/profile and/etc/environment
1) add export LANG = zh_CN to/etc/profile, log out of the system and log on again. The logon prompt is in English.
2) delete export LANG = zh_CN in/etc/profile, add LNAG = zh_CN to/etc/environment, log out of the system and log on again. The logon prompt displays Chinese characters.
When the user environment is established, the/etc/profile is always executed first, and then the/etc/environment is read. Why is there a difference as described above? Instead of executing/etc/environment first and then/etc/profile?
This is because/etc/environment sets the entire system environment, while/etc/profile sets the environment for all users. The former has nothing to do with the login user, and the latter is related to the login user.
The execution of system applications may be unrelated to the user environment, but related to the system environment. Therefore, when you log on, you will see the prompt information, for example, the display format of date and time information is related to the LANG in the system environment. the default format is LANG = en_US. if the system environment LANG = zh_CN, the system prompts that the information is in Chinese, otherwise, it is in English.
For shell initialization, run/etc/profile first and then read the file/etc/environment. for the whole system, run/etc/environment first. Is this true?
The system login sequence should be
/Etc/enviroment -->/etc/profile --> $ HOME/. profile --> $ HOME/. env (if any)
/Etc/profile is the environment variable of all users
/Etc/enviroment is the system environment variable
The sequence of shell reading when logging on to the system should be
/Etc/profile->/etc/enviroment --> $ HOME/. profile --> $ HOME/. env
The reason should be the difference between the user environment and the system environment. if the same variable has different values in the user environment (/etc/profile) and the system environment (/etc/environment, this should be based on the user environment.