How unset a lot of environment variables

unset takes multiple variables:

unset HTTP_PROXY HTTPS_PROXY FTP_PROXY ALL_PROXY NO_PROXY

A little bit late, but anyway. Depending on your variable pattern you can shorten your unset:

  1. List your variables. For example, depending on your scope you can do it with env or compgen -v.
  2. Filter for desired variables. For example with grep or sed.
  3. Pass the variables to unset.

For example in your case it can be:

unset $(compgen -v | grep "_PROXY$")

It's not exactly one command, but it imitates unset *_PROXY, as you requested in your comment.


Using babashka:

bb -o '(->> (System/getenv)
            keys
            (filter #(str/ends-with? % "_PROXY"))
            (map #(str "unset " %)))' | 
  source /dev/stdin

Tags:

Linux

Unset