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

How to delete environment variables in linux

WBOY
Release: 2022-03-11 15:18:43
Original
21548 people have browsed it

In Linux, you can use the unset command to delete environment variables. This command is used to delete variables or functions. The syntax is "unset variable name"; when using the unset command to delete environment variables in a shell subprocess, only Affects the visibility of the current child process and does not affect the parent shell process.

How to delete environment variables in linux

#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.

How to delete environment variables in Linux

1. Delete global environment variables

The test_val=my_test_dog variable added in the /etc/profile file is a For global environment variables, you can use the unset command to delete this global environment variable. The command is as follows:

echo $test_val
unset test_val
echo $test_val
Copy after login

The execution result is as shown below:

How to delete environment variables in linux

##Tips: Because of the test_val variable The value is in the file /etc/profile. After being deleted by the unset command, you can re-use the source /etc/profile command to update the permissions and re-obtain the value of the test_val variable.

2. Delete environment variables in the shell sub-process

You can use the unset command to delete the specified environment variable name in the shell sub-process. The command is as follows:

new_val="5axxw"
export new_val
bash
echo $new_val
unset new_val
echo $new_val
exit
echo $new_val
Copy after login
The execution result is as follows:

How to delete environment variables in linux

3. Summary

This section mainly introduces how to use the unset command to delete environment variables , it should be noted that global environment variables visible in the shell child process, deletion using the unset command only affects the visibility of the current child process, and will not affect the parent shell process. In addition, generally when using environment variables, the variable name must be preceded by $. If the variable is operated, the preceding $ is not required.

Related recommendations: "

Linux Video Tutorial"

The above is the detailed content of How to delete 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