-->

Removing Environment Variables

Removing Environment Variables
Removing Environment Variables


Of course, if you can create a new environment variable, it makes sense that you can also remove an existing environment variable. You can do this with the unset command. When referencing the environment variable in the unset command, remember not to use the dollar sign:

$ echo $my_variable
I am Global now
$$
unset my_variable
$$
echo $my_variable
$

Tip
It can be confusing to remember when to use and when not to use the dollar sign with environment variables. Just remember this: If you are doing anything with the variable, use the dollar sign. If you are doing anything to the variable, don’t use the dollar sign. The exception to this rule is using printenv to display a variable’s value.

When dealing with global environment variables, things get a little tricky. If you’re in a child process and unset a global environment variable, it applies only to the child process.

The global environment variable is still available in the parent process:

$ my_variable=“I am Global now”
$$
export my_variable
$$
echo $my_variable
I am Global now
$$
bash
$$
echo $my_variable
I am Global now
$$
unset my_variable
$$
echo $my_variable
$ exit
exit
$$
echo $my_variable
I am Global now
$

Just as with modifying a variable, you cannot unset it in a child shell and have the variable
be unset in the parent’s shell.

0 Response to "Removing Environment Variables"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel