Linux/etc/profile ,~ /. Execution Process of several files such as bash_profile

Source: Internet
Author: User

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 followingCode:
If [-f ~ /. Bashrc]; then
../Bashrc
Fi

~ /. Bashrc usually has the following code:
If [-F/etc/bashrc]; then
./Bashrc
Fi

So ,~ /. Bashrc calls the/etc/bashrc file. Finally, when you exit the shell, ~ /. Bash_logout file.

The execution sequence is as follows:/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, the file is executed and shell settings are collected from the configuration file in the/etc/profile. d directory.

(2)/Etc/bashrc:Execute this file for every user running bash shell. When 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 own 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 each time you open a new shell.

(5)~ /. Bash_logout:Execute this file every time you exit the system (exit bash shell). In addition, the variables set in/etc/profile (global) 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:Is interactive, login mode to enter Bash to run ~ /. 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

Add export lang = zh_cn to/etc/profile, log out of the system, and log on again. The logon prompt is in English.

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?

Run/etc/environment first and then/etc/profile.

/Etc/environment is used to set the environment of the entire system, while/etc/profile is used to set the environment of all users. The former has nothing to do with the login user, and the latter has to do with the login user.

System ApplicationProgramThe execution is irrelevant to the user environment, but it is related to the system environment. Therefore, when you log on, you will see the prompt information, the display format of date and time information is related to the Lang in the system environment. The default is lang = en_us. If the system environment lang = zh_cn, the message is displayed 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?

/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 mentioned by jtw.

If the same variable has different values in the user environment (/etc/profile) and system environment (/etc/environment), the user environment should prevail.

 

Reprinted statement:This article from http://blog.csdn.net/dingxy/archive/2009/03/23/4016383.aspx

 

========================================================== ======================================

 

Extension reference:

Linux environment variables

Bash again shell Startup File

ADB environment variable configuration for Ubuntu

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.