Christopher Schene
asked on
Need a way to clear out Linux env variables
I would like to delete all the environment variables in my LINUX session and then set all the env variables to a set of values I choose.
250 points for help
500 for code that does what I need. Could be Shell script, perl, c++
250 points for help
500 for code that does what I need. Could be Shell script, perl, c++
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
> only clears the env variables for the current login session
Yes. it only clear the current shell session.
Yes. it only clear the current shell session.
in bourne shells,
env -i
may help too
ASKER
I tried the loop before and I have uploaded the before and after env values
Is this what you would expect?
for VAR in `/usr/bin/env | egrep '^(\w+)=(.*)$' | egrep -vw 'PWD|USER|LANG|_' | /usr/bin/cut -d= -f1`
do
unset $VAR
done
Before executing the loop
env-before-clear.txt
After executing the loop
env-after-clear.txt
Is this what you would expect?
for VAR in `/usr/bin/env | egrep '^(\w+)=(.*)$' | egrep -vw 'PWD|USER|LANG|_' | /usr/bin/cut -d= -f1`
do
unset $VAR
done
Before executing the loop
env-before-clear.txt
After executing the loop
env-after-clear.txt
The env-after looks good to me.
Any specific environment variable you don't want and it still exist?
Try manually run "unset <env variable name>" to see if you can unset or not.
Any specific environment variable you don't want and it still exist?
Try manually run "unset <env variable name>" to see if you can unset or not.
ASKER
increasing points
ASKER
Great solution, fast response.
ASKER
thanks for the fast response.
Just to clarify: This only clears the env variables for the current login session, correct?
Thanks,
Chris Schene