environment variable Background
Linux is a multi-user operating system, each user logged into the system, there is a dedicated operating environment, usually the default environment variables for each user is the same, users can modify their own environment variables to achieve custom purposes. Environment variables are closely related to the shell, the user login system is to start a shell, for Linux is generally bash, you can reset or switch. Depending on the release, Bash has two basic system-level configuration files:/etc/profile,/ETC/BASHRC. These configuration files contain two different sets of variables: Shell variables and environment variables, shell variables are local, environment variables are global.
setting, using Variables
1 , display environment variables
Echo $PATH
2. Setting and modifying environment variables
Export test_path= "/tmp"
3. Show all environment variables
Env
4. Show locally defined shell variables
Set
5. Set read-only
ReadOnly Test_path
6. Clear Environment variables
Unset Test_path
7. Modify File Settings environment variables
Modify the. bash_profile file, the source command in the user's home directory to make the environment variable effective
Vim ~/.bash_profile & Source ~/.bash_profile
Summary
I. Types of variables
1, Permanent: Modify the configuration file, the permanent effect;
2. Temporary: Export command declaration, close Shell invalidation
Ii. three ways to set up variables
| Method |
Role user |
Effect Aging |
| Vim/etc/profile & Source |
All Users |
Permanent effect |
| Vim ~/.bash_profile & source |
Current user |
Permanent effect |
| Export definition Variables |
Current Shell |
Temporary, disable after shell is closed |
Linux Setting Environment variables