Before going into erasing variables, I will show you how to demote an environment variable to become a local variable.
You can achieve the demotion by using the "-n" switch with the export
command. This will also preserve value of your variable. You can do that as in the following example:
testuser1@testuser1-host:~$ export -n testvariable2 testuser1@testuser1-host:~$ echo $testvariable2 value2 testuser1@testuser1-host:~$ env | grep testvariable2 testuser1@testuser1-host:~$ printenv testvariable2
As you can see in the above example, you can use the echo
command to see the value of the variable, but once it has been demoted, the printenv
and env
commands will result in no output.
In order to completely erase the existence of a variable (regardless the type, environment or local), you will have to use the unset
command. Once erased, the printenv
, env
and even the echo
commands will result in no output.
testuser1@testuser1-host:~$ unset testvariable testuser1@testuser1-host:~$ env | grep testvariable testuser1@testuser1-host:~$ printenv testvariable testuser1@testuser1-host:~$ echo $testvariable