Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reset all environment variables?

I want to do :

env | egrep -o '^\w+=' | unset

The problem is that :

env | egrep -o '^\w+='

prints things like (notice the equal sign) :

XDG_VTNR= LC_PAPER= SSH_AGENT_PID= KDE_MULTIHEAD= LC_ADDRESS= XDG_SESSION_ID=

How do I extract just the variable names so I can unset them?

like image 279
Belun Avatar asked Apr 02 '14 15:04

Belun


Video Answer


1 Answers

You need something more like this:

for i in `env | sed 's/=.*//'` ; do
    unset $i
done

Note, however, this will probably do more things than you want. EG, it'll unset your path too!

like image 184
Wes Hardaker Avatar answered Sep 21 '22 09:09

Wes Hardaker