Environment variables include system environment variables and user environment variables. System environment variables work for all users, while user environment variables only work for the current user. System environment variables:
/Etc/profile: 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. and from/etc/profile. the configuration file in the d directory Collects shell settings.
/Etc/bashrc: execute this file for every user running bash shell. When bash shell is opened, the file is read.
Current user variable:
~ /. Bash_profile: 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! By default, it sets some environment variables to execute the user's. bashrc file.
~ /. Bashrc: This file contains bash information dedicated to your bash shell. This file is read when you log on and every time you open a new shell.
~ /. Bash_logout: execute this file every time you exit the system (exit bash shell.
1. What are environment variables?
Linux is a multi-user operating system. Multiple users mean that each user has a dedicated runtime environment after logging on to the system. This environment is defined by a group of variables, which are called environment variables. You can modify your environment variables to meet the environment requirements.
Ii. customized Environment Variables
Environment variables are closely related to shell, which are set through shell commands. Environment variables can be run by all current users Program Used. For Bash, you can use the variable name to access the corresponding environment variables.
The following examples are used to describe
1. display the environment variable home
$ Echo $ home
/Home/admin
2. Set a new environment variable name
$ Export name =
" Raidcheng
"
$ Echo $ name
Raidcheng
3. Use the Env command to display all environment variables
$ ENV
Hostname = test
Term = VT100
Shell =/bin/bash
History Size = 1000
Ssh_client = 202. XXX 53694 22
Catalina_base =/usr/local/Jakarta-Tomcat
Ssh_tty =/dev/pts/0
Ant_home =/usr/local/ant
Java_opts =-Server
User = Admin
...
4. Use the SET command to display all locally defined shell Variables
$ Set
Bash =/bin/bash
Bash_versinfo = ([0] =
" 2
" [1] =
" 05b
" [2] =
" 0
" [3] =
" 1
" [4] =
" Release
" [5] =
" I386-redhat-linux-gnu
" )
Bash_version =
' 2.05b.0 (1)-release
'
Catalina_base =/usr/local/Jakarta-Tomcat
Catalina_home =/usr/local/Jakarta-Tomcat
...
5. Run the unset command to clear environment variables.
$ Export name =
" Raidcheng
"
$ Echo $ name
Raidcheng
$ Unset name
$ Echo $ name
6. Use the readonly command to set the read-only variable
$ Export name =
" Raidcheng
"
$ Readonly name
$ Unset name
-Bash: unset: Name: cannot unset: readonly variable
$ Name =
" New
" # This variable cannot be modified.
-Bash: Test: readonly variable
Iii. Common Environment Variables
Path determines the directories to which shell will look for commands or programs.
Home main directory of the current user
Histsize
LOGNAME: The Login Name of the current user.
Hostname indicates the host name.
Shell Type before Shell
Languge language-related environment variables, which can be modified in multiple languages
Mail current user's mail storage directory
PS1 basic prompt, for root users is #, for common users is $
PS2 affiliated prompt. The default value is ">"
LinuxIs a multi-user operating system. Every user logs on to the systemThere will be a dedicated runtime environment. Generally, the default environment of each user is the same. The default environment is actually the definition of a set of environment variables. You can customize your running environment by modifying the corresponding system environment variables..
Environment variables areShellClosely related, user login SystemThen a shell is started.. ForLinuxGenerallyBashBut you can reset or switch to anotherShell. Environment variables areShellCommand to set, SetEnvironment variables can be used by all programs run by the current user. ForBashThisShellProgram, you can access the correspondingEnvironment variable, through exportTo set environment variables.
You can also modify the environment variables by modifying some related environment definition files. For exampleRed HatAnd so onLinuxReleased version. Environment-related files include/Etc/profileAnd~ /. Bashrc. ModifiedAfterA new logon takes effect..
/Etc/profile:This file sets the environment information for each user of the system.,When a user logs on for the first time,This file is executed.
And from/Etc/profile. dDirectory configuration file collectionShellSettings.
/Etc/bashrc:For every runningBashShellThe user executes this file.WhenBashShellWhen opened,This file is read.
~ /. Bash_profile:Each user can use this file to inputShellInformation,When a user logs on,This file is only executed once!By default,It sets some environment variables,Executed user's. BashrcFile.
~ /. Bashrc:This file contains yourBashShellOfBashInformation,When you log on and each time you open a newShellHour,The
This file is read.
UseExportThe command can be used to set environment variables.It is annoying to reset the environment variable again later.LinuxProvideThe method for automatically setting environment variables is changed.. BashrcFile. Generally, there are two files that can provide the "automatically set when entering the system" function. One is/Etc/bashrcAnd the other is~ /. Bashrc. Where/Etc/bashrcIs executed by each user, and~ /. BashrcOnly executed by the current user. So/Etc/bashrcOnlyRootUsers can change, while~ /. BashrcIs a private file of each user."~ "It refers to the user'sHomeDirectory.
ExportJust addEnvironment Variables temporarily exist in the memory, restart or open a new shellSessionThen there is no solution:
1.Modify/Etc/profile
After the restart, the environment variable is still there. But this is not recommended because this setting will apply to the shell of all users.All take effect, which will affect system security.
2.Modify~ /. BashrcFile