How does the UbuntuLinux system set environment variables?

Source: Internet
Author: User
Note: my own method is to modify bash in the/etc directory. bashrcAdd: PATH $ PATH:/usr/local/bin/arm-linux-gcc-4.4.3/bin/andnextisothermethods: environment variables are closely related to Shell, and a Shell is started after the user logs on to the system. For Linux, it is generally bas.

Note:

My own method is: modify bash. bashrc under the/etc directory.

Add:

PATH = $ PATH: "/usr/local/bin/arm-linux-gcc-4.4.3/bin /"

And next is other methods:

Environment variables are closely related to Shell. a Shell is started after the user logs on to the system. For Linux, bash is generally used, but you can reset or switch to another Shell. For UNIX, it may be CShelll. Environment variables are set through Shell commands. the configured environment variables can be used by all programs run by the current user. For the bash Shell program, the corresponding environment variables can be accessed through the variable name, and the environment variables can be set through export. The following describes several instances.

1) etc/profile: This file sets environment information for each user in the system. when the user logs on for the first time, this file is executed.
And collect shell settings from the configuration file in the/etc/profile. d Directory.
Note: Here we set global variables that can be used by all users.

2)/etc/bashrc:Execute this file for every user running bash shell. when bashshell is opened, the file is read.

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 only executed once!By default, it sets some environment variables to execute the user's. bashrc file.
Note :~ In LINUX, the variable HOME is represented.
In addition, in different LINUX operating systems, this file may be different ~ /. Bash_profile ;~ /. Bash_login or ~ /. One or more of the profiles. if there are several, the execution sequence is :~ /. Bash_profile ,~ /. Bash_login ,~ /. Profile. For example, if I use Ubuntu, only ~ is used by default in my user folder ~ /. Profile file.

4 )~ /. Bashrc:This file contains bash information dedicated to your bashshell. when you log on and open a new shell, the file is read.
(Note: This file starts with., so it is hidden in the folder)
So how do we add our own defined environment variables?
Open the file in notepad, and then write:
Xiaokang = kangkang
Save the variable so that each time a new terminal is opened, this variable takes effect. Remember, if you have opened a terminal and modified the file, it will not take effect under this terminal.
In general, you 'd better modify it here, but sometimes it will overwrite the parent-level variables. for example, if PATH is set as ROOT, but if you write PATH = xx in this file, in the future, all the paths will become xx, so we should write the following in this file:
PATH = $ PATH: xx
In this way, we can add the original and your own. In addition, in LINUX, use: to split and represent parallel, rather than windo;
Both 3 and 4 are in the user directory. The only difference is that. bash_profile can only be started once at login. This 3 file does not seem to exist in my Ubuntu.

5 )~ /. Bash_logout:Execute this file every time you exit the system (exit bash shell.
In addition, the variables (global) set in/etc/profile can act on any user ~ The variables (local) set in/. bashrc and so on can only inherit the variables in/etc/profile. they are the/"parent-child/" relationship.

~ /. Bash_profile is interactive and login to run in bash.
~ /. Bashrc runs in bash in interactive non-login mode.
Generally, the two settings are roughly the same, so the former usually calls the latter.

Okay. Let's summarize their execution methods:
When you log on to and log on to shell as bash, bash first executes the command in the/etc/profile File (if the file exists), and then searches ~ /. Bash_profile ,~ /. Bash_login or ~ /. Profile file, and execute the command in the first readable file found. when you log on to bash and exit, it will execute ~ /. Bash_logout file.
When an interactive bash is started, it will execute ~ /. Commands in the bashrc file (if the file exists and is readable). when a shell script is started non-interactively, bash searches for the bash_env environment variable and determines the name of the execution file.

Related Article

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.