Home > Operation and Maintenance > Linux Operation and Maintenance > How to view environment variables in linux

How to view environment variables in linux

醉折花枝作酒筹
Release: 2023-01-06 11:15:09
Original
75518 people have browsed it

Method: 1. Use the echo command to display known environment variables, the syntax "$ echo variable"; 2. Use the env command to display all environment variables, the syntax "$ env"; 3. Use the set command to display All locally defined Shell variables, syntax "$set".

How to view environment variables in linux

#The operating environment of this tutorial: centos7 system, thinkpad t480 computer.

Display known environment variables

For example:

$ echo $HELLO 
echo $JAVA_HOME
Copy after login

Use env command to display all environment variables

 $ env
Copy after login

Use set command to display all locally defined environment variables Shell variables

$ set
Copy after login

Use the unset command to clear environment variables

set can set the value of an environment variable. To clear the value of an environment variable, use the unset command. If no value is specified, the variable value will be set to NULL. Examples are as follows:

$ export TEST="Test..."       #增加一个环境变量TEST 
$ env|grep TEST       #此命令有输入,证明环境变量TEST已经存在了 
TEST=Test... 
$ unset $TEST          #删除环境变量TEST 
$ env|grep TEST      #此命令没有输出,证明环境变量TEST已经存在了
Copy after login

Use the readonly command to set read-only variables

If the readonly command is used, the variables cannot be modified or cleared. Examples are as follows:

$ export TEST="Test..."       #增加一个环境变量TEST 
$ readonly TEST                 #将环境变量TEST设为只读 
$ unset TEST                       #会发现此变量不能被删除 
-bash: unset: TEST: cannot unset: readonly variable 
$ TEST="New"                    #会发现此也变量不能被修改 
-bash: TEST: readonly variable
Copy after login

(Recommended learning: linux tutorial)

The above is the detailed content of How to view environment variables in linux. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template