Operating System - HP-UX
1832676 Members
2836 Online
110043 Solutions
New Discussion

Clearing all session environment variables

 
wvsa
Regular Advisor

Clearing all session environment variables

Does anyone know of a way that I can clear (unset) all of the environment variables set in a session? I'm hoping for something more elegant than a loop based on env doing individual unsets
5 REPLIES 5
Steven Sim Kok Leong
Honored Contributor

Re: Clearing all session environment variables

Hi,

Btw, you will not be able to clear READONLY environment variables unless you are root.

Hope this helps. Regards.

Steven Sim Kok Leong
Zach Parker
Occasional Advisor

Re: Clearing all session environment variables


Well, if you just want to execute a command without any environmental variables, you can do:
env -i
using:
env -i /usr/bin/ksh
would get you a shell sans your previous environemnt.
Peter Kloetgen
Esteemed Contributor

Re: Clearing all session environment variables

Hi,

what you want seems to be critical in my opinion. When leaving a session, you want to "unset" *all* environment variables??? This is not good, because a lot of these variables are necessary for your system to run. With a unset- command you will not unset the system-environment variables like PATH, TZ. These variables are protected, they can't be simply unset. If you created own variables, and exported them, they will be lost automatically when you finish the shell in which you created them. And if you changed values for any system variables, the old value, from before your session will be actual again, when you finish the shell.

Allways stay on the bright side of life!

Peter
I'm learning here as well as helping
Niraj Kumar Verma
Trusted Contributor

Re: Clearing all session environment variables

hi,

try

# unset variable_name

-Niraj
Niraj.Verma@philips.com
Deepak Extross
Honored Contributor

Re: Clearing all session environment variables

Do you mean that you want to revert to the environment set during login?
There's no easy way to do this - the best workaround I can think of is to simply logout and login again.