Linux | sequence of bash environment variables in UNIX

Source: Internet
Author: User
Files related to bash environment settings include:
/Etc/profile (main)
$ Home/. bash_profile (main)
$ Home/. bash_login
$ Home/. Profile
$ Home/. bash_logout (main)
$ Home/. bashrc (main)
/Etc/bashrc

Description:
* Login
# Run/etc/profile first
# Bash then checks whether. bash_profile,. bash_login, or. profile exists in the user's own directory. If yes, bash executes one of them in the following order:
#. Bash_profile top priority
#. Bash_login followed
#. Last Profile
These three files will be read by bash only when they are logged in.

* When logging out (exit/logout ),
Bash checks whether the user's own directory contains. bash_logout. If yes, bash executes the command

* Start a new shell after logging in:
In this case, we call it a subshell. That is to say, in the Command column, we typed Bash. In addition to the bash at the original logon, we started a new bash shell.
Bash checks whether the user's own directory contains. bashrc. If yes, execute

* Test:
Add the echo command to each file to observe the execution sequence.

Usage of each document
*/Etc/profile is controlled by the root user and is used to set the shell environment suitable for all users.
* If the user does not agree with the/etc/profile setting, modify. bash_profile in the home directory.
* Now that we have. bash_profile, why should we have. bash_login and. profile? This is because some people may have migrated from the Bourne shell, as long as the main Startup File of The Bourne shell is changed. the profile is moved to its own directory and is not used. bash_profile and. bash_login can continue to use the previously set Environment
*. The reason for bash_login may be related to c shell, but the syntax of Bash and C shell is not completely compatible. Therefore, we do not recommend that you directly use the C shell Startup File.
*. Bashrc is used to set the subshell environment. bashrc re-executes/etc/profile once for subshell-free generation. we found that. in bashrc, the/etc/bashrc command has been executed in advance. This indicates that the root may set the environment when the subshell is generated. The user only needs to keep the/etc/bashrc content, there should be no problems.
*. Bash_logout is the configuration file that will be executed before the user logs out of the host. If the user wants to automatically handle some things after logging out of the system, such as clearing temporary files and clearing the screen, you can set it in this file.

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.