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".
#The operating environment of this tutorial: centos7 system, thinkpad t480 computer.
Display known environment variables
For example:
$ echo $HELLO echo $JAVA_HOME
Use env command to display all environment variables
$ env
Use set command to display all locally defined environment variables Shell variables
$ set
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已经存在了
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
(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!