如何重置所有环境变量?

时间:2023-02-02 22:45:20

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=

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?

如何仅提取变量名称以便我可以取消它们?

1 个解决方案

#1


6  

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!

但请注意,这可能会比您想要的更多。 EG,它也会破坏你的道路!

#1


6  

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!

但请注意,这可能会比您想要的更多。 EG,它也会破坏你的道路!