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.
#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.
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
The execution result is as shown below:
##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
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!