linux - [Solved-2 Solutions] How to delete (unset) an exported environment variable ? - ubuntu - red hat - debian - linux server - linux pc




Linux - Problem :

How to delete (unset) an exported environment variable ?

Linux - Solution 1:

unset GNUPLOT_DRIVER_DIR
click below button to copy the code. By - Linux tutorial - team

Linux - Solution 2:

Creating and deleting an environment variable in bash:

Test if the DUALCASE variable exists:

[email protected]:~$ env | grep DUALCASE
[email protected]:~$ 
click below button to copy the code. By - Linux tutorial - team

It does not, so create the variable and export it:

[email protected]:~$ DUALCASE=1
[email protected]:~$ export DUALCASE
click below button to copy the code. By - Linux tutorial - team

Check if it is there:

[email protected]:~$ env | grep DUALCASE
DUALCASE=1
click below button to copy the code. By - Linux tutorial - team
[email protected]:~$ unset DUALCASE
click below button to copy the code. By - Linux tutorial - team

Check if it's still there:

[email protected]:~$ env | grep DUALCASE
[email protected]:~$ 
click below button to copy the code. By - Linux tutorial - team

The DUALCASE exported environment variable is deleted.

Extra commands to help clear your local and environment variables:

Unset all local variables back to default on login:

[email protected]:~$ CAN="wikitechy"
[email protected]:~$ set | grep CAN
CAN='wikitechy'
[email protected]:~$ env | grep CAN
[email protected]:~$
[email protected]:~$ exec bash
[email protected]:~$ set | grep CAN
[email protected]:~$ env | grep CAN
[email protected]:~$
click below button to copy the code. By - Linux tutorial - team

exec bash command cleared all the local variables but not environment variables.

Unset all environment variables back to default on login:

[email protected]:~$ export DOGE="welcome to wikitechy"
[email protected]:~$ env | grep DOGE
DOGE=welcome to wikitechy
[email protected]:~$ env -i bash
[email protected]:~$ env | grep DOGE
[email protected]:~$
click below button to copy the code. By - Linux tutorial - team

env -i bash command cleared all the environment variables to default on login.


Related Searches to - linux - linux tutorial - How to delete (unset) an exported environment variable ?