Article Title: Setting and storing linux environment variables. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
1. display the environment variable HOME
$ Echo $ HOME
/Home/redbooks
2. Set a new environment variable hello
$ Export HELLO = "Hello! "
$ Echo $ HELLO
Hello!
3. Use the env command to display all environment variables
$ Env
HOSTNAME = redbooks.safe.org
PVM_RSH =/usr/bin/rsh
SHELL =/bin/bash
TERM = xterm
History Size = 1000
...
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'
COLORS =/etc/DIR_COLORS.xterm
COLUMNS = 80
DIRSTACK = ()
DISPLAY =: 0.0
...
5. Run the unset command to clear environment variables.
Set can be used to set the value of an environment variable. Run the unset command to clear the environment variable values. If no value is specified, the variable value is set to NULL. Example:
$ Export TEST = "Test..." # Add an environment variable TEST.
$ Env | grep TEST # This command is input to prove that the environment variable TEST already exists.
TEST = Test...
$ Unset $ TEST # Delete the environment variable TEST
$ Env | grep TEST # This command is not output, proving that the environment variable TEST already exists
6. Use the readonly command to set the read-only variable
If the readonly command is used, the variables cannot be modified or cleared. Example:
$ Export TEST = "Test..." # Add an environment variable TEST.
$ Readonly TEST # Set the environment variable TEST as read-only
$ Unset TEST # This variable cannot be deleted
-Bash: unset: TEST: cannot unset: readonly variable
$ TEST = "New" # This variable cannot be modified.
-Bash: TEST: readonly variable
The environment variable settings are in the/etc/profile file.
If you want to add new environment variables, you can add subordinate lines.
Export path = $ path:/path1:/path2:/pahtN