Comparison Between/etc/profile and/etc/enviroment about four environment variables of ubuntu

Source: Internet
Author: User

Add export lang = zh_cn to/etc/profile, log out of the system, and log on again. The logon prompt is in English. Set/etc/profile
Delete export lang = zh_cn, add lnag = zh_cn to/etc/environment, log out of the system and log on again. The logon prompt displays Chinese characters.

Use
The/etc/profile is always executed before/etc/environment is read. Why is there a difference as described above??


Should
Is to first execute/etc/environment, and then execute/etc/profile.

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

The execution of system applications is irrelevant to the user environment.
But it is related to the system environment,

So when you log on, the prompt information you see, such as the display format of date and time information is related to the Lang of the system environment. The default lang = en_us, such
If the system environment lang = zh_cn, the system prompts that the information is in Chinese. Otherwise, the information is in English.

For Shell initialization, run/etc/profile first,
Then read the file/etc/environment.

For the entire system, execute/etc/environment first. Is this correct??




/Etc/Enviroment
-->/Etc/profile --> $ home/. Pro

File --> $ 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

Original
This is because the difference between the user environment and the system environment mentioned by jtw.

If the same variable is in the user environment (/etc/profile) and system environment (/etc/environment)
The value varies depending on the user environment.

(1)/etc/profile:
This file is for every user of the system.
Set the environment information. 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.

(3 )~ /. Bash_profile:

Each user can use this file to input a dedicated user
The shell information used. When a user logs on, this file is executed only once! By default, it sets some environment variables and executes the user
. Bashrc file.

(4 )~ /. Bashrc: This file contains
Bash
Bash information of the shell. The file is read at login and every time a new shell is opened.

(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
To act on any user, and ~ The variables (local) set in/. bashrc and so on can only inherit the variables in/etc/profile, they are "Parent and Child" off
System.

(6 )~ /. Bash_profile
Is interactive, login mode to enter Bash to run ~ /. Bashrc enters bash in interactive non-login mode.
Generally, the two running settings are roughly the same, so the former usually calls the latter.

After comparison, we found that the settings represented
.

$ Sudo Vim/etc/profile

Add at the end of the file

# Set Java
Environment

Java_home =/opt/jdk1.6.0 _ 07

Export
Jre_home =/opt/jdk1.6.0 _ 07/JRE

Export
Classpath =.: $ java_home/lib: $ jre_home/lib: $ classpath

Export
Path = $ java_home/bin: $ jre_home/bin: $ path

Finally, WQ!

Note: Run
Shell provides a set of environment variables. Export allows you to add, modify, or delete environment variables for subsequent programs. The effect of export is only true for this login operation.

######################################## ###########################

The file execution process when logging on to Linux is as follows:
When logging on to Linux, start
/Etc/profile file, and then start ~ /. Bash_profile ,~ /. Bash_login or
~ /. One of the profile files is executed in the following sequence :~ /. 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:

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

So ,~ /. Bashrc will call
/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

######################################## #########################

 

1. log on to Shell
The shell used to log on to the system is the shell used to log on to the system. The logon shell is an interactive shell.

Log on to the shell and find four startup files to process the commands. The order in which bash shell processes files is as follows:
1:
/Etc/profile

2:/etc/profile. D. Wait for the configuration file

3: $ home/. bash_profile

4: $ home/. bash_login
5 $ home/. Profile
 
/Etc/profile is the main default startup file of bash shell on the system. Every user on the system will execute this file upon login. By setting this file, the Super User can create
Recognize features. Different Linux versions place different commands in this file. In redflag, this file sets several important changes
Number, for example, path user LOGNAME
Mail hostname histsize inputrc. For details, you can view the specific file. Fc11 NBW-blog ztag js-fs2 ">
The remaining three files have the same functions-provide user-specific startup files. Mostly
In Linux, only one of them is used. For example, redflag uses. bash_profile for Ubuntu. profile.
Shell
Search ~ /. Bash_profile ,~ /. Bash_login ,~ /. Profile (~ Is the stenographer of the user's home directory.
And execute the command in the first file it finds. You can place commands in these files to overwrite/etc.
/Profile file. That is, the subsequent files can overwrite or modify the previous settings.
. 2. Interactive non-Logon Shell
If you start
A bash shell instead of a record system (such as typing bash at the CLI prompt), an interactive non-Logon shell is started. fc11 NBW-blog ztag js-fs2 "> and login shell initialization file (such. bash_profile) usually runs this file. In this way,
You can use the. bashrc command to log on to shell and non-Logon shell. For example
When logging on to Linux in windows, the terminals started in X environment are non-Logon shells.
In the interactive non-Logon shell, do not execute
. However, the interactive non-Logon shell inherits the shell variables set by these initialization files from the logon shell.
(1)
$ Home/. bashrc
Interactive non-Logon shell execution
Line ~ The command in the/. bashrc file. This file will be re-read every time the shell script is executed, so it is the most complete. But everything is not the same, debain Series
Is different, such as Ubuntu/etc/profile -->/etc/environment --> $ home /. the environment variable configuration file of profileubuntu Linux contains the following files for setting the environment variable/etc/profile: during login, the operating system
The first file used for customized user environments
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. /Etc
/Environment: the second file used by the operating system during logon,
The system sets the environment variable of the Environment file before reading your own profile .~ /. Profile:
The third file used for Logon
Yes. profile file. Each user can use this file to input the shell information dedicated to their own use. When a user logs on, this file is only executed once! Default
In this case, it sets some environment variables to execute the user's. bashrc file. /Etc/bashrc: Run bash for each
Shell users execute this file. When bash shell is opened, this file is read .~ /. Bashrc: This file contains your Bash
Bash information of the shell. The file is read at login and every time a new shell is opened.

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.