"Turn" Linux/etc/profile, ~/.bash_profile and several other files of the implementation process

Source: Internet
Author: User

Original URL: http://blog.csdn.net/ithomer/article/details/6322892

The procedure to execute a file when logging on to Linux is as follows:
When you first log in to Linux, start the/etc/profile file, and then start one of the ~/.bash_profile, ~/.bash_login, or ~/.profile files in the user directory,

The order of execution is: ~/.bash_profile, ~/.bash_login, ~/.profile.

If the ~/.bash_profile file exists, the ~/.BASHRC file is typically executed.

Because the following code is commonly found in the ~/.bash_profile file:
If [-f ~/.BASHRC]; Then
. ./BASHRC
Fi

In ~/.BASHRC, the following code is generally available:
if [-F/ETC/BASHRC]; Then
. /etc/bashrc
Fi

Therefore, ~/.BASHRC will call the/ETC/BASHRC file. Finally, when you exit the shell, the ~/.bash_logout file is also executed.

Order of execution:/etc/profile---(~/.bash_profile | ~/.bash_login | ~/.profile), ~/.BASHRC,/ETC/BASHRC, ~/.bash_l Ogout

For the scope of each file, the following instructions were found on the Web:

(1)/etc/profile:This file sets the environment information for each user of the system, and the file is executed when the user logs on for the first time. and collect the shell settings from the configuration file of the/ETC/PROFILE.D directory.

(2)/ETC/BASHRC:Execute this file for each user running the bash shell. When the bash shell is opened, the file is read (that is, each time a new terminal is opened, BASHRC is executed).

(3)~/.bash_profile:Each user can use the file to enter shell information that is specific to their own use, which is performed only once when the user logs on. 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, which is read when you log in and every time you open a new shell.

(5)~/.bash_logout:Executes the file each time it exits the system (exiting the bash shell). In addition, the variables set in/etc/profile (global) can be applied to any user, while the variables set in ~/.BASHRC, etc. (local) only inherit variables from/etc/profile, they are "parent-child" relationships.


(6) ~/.bash_profile: is interactive, login way into bash run ~/.BASHRC is the interactive non-login way into the bash run usually the two settings are roughly the same, so the former will usually call the latter.


The use of various environment variable settings files such as/etc/profile and/etc/environment

1) First add the export LANG=ZH_CN to/etc/profile, exit the system login, login prompt display in English.

2) First delete the/etc/profile in the export lang=zh_cn, add LNAG=ZH_CN to/etc/environment, log out of the system to log in, the login prompt to display Chinese.


The user environment is established by always executing the/etc/profile before reading the/etc/environment. Why is it as different as the above? Instead of executing/etc/environment first, then executing/etc/profile?
This is because/etc/environment is an environment that sets up the entire system, and/etc/profile is the environment for setting up all users, regardless of the logged-on user, which is related to the logged-on user.

The execution of the system application can be irrelevant to the user environment, but it is related to the system environment, so when you log in, you see the display format of information such as date, time information and the system environment of Lang is related, default Lang=en_us, if the system environment LANG=ZH_CN, The message is in Chinese, otherwise it is in English.


For the user Shell initialization is the first execution/etc/profile, then read the file/etc/environment, for the entire system is the first to execute/etc/environment. Do you understand that correctly?
The order in which the system is logged should be

/etc/enviroment--/etc/profile-$HOME/.profile--$HOME/.env (if present)
/etc/profile is the environment variable for all users
/etc/enviroment is the environment variable of the system


The order in which the shell reads the system when logging in 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 in the user environment (/etc/profile) and the system environment (/etc/environment) have different values, it should be based on the user environment.

Extension reference:

Linux environment variables

Bash again Shell's startup file

Ubuntu's ADB environment variable configuration

"Turn" Linux/etc/profile, ~/.bash_profile and several other files of the implementation process

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.