How to Delete an Exported Environment Variable

How do I delete an exported environment variable?

unset is the command you're looking for.


Is it possible to change the Environment of a parent process in Python?

No process can change its parent process (or any other existing process' environment).

You can, however, create a new environment by creating a new interactive shell with the modified environment.

You have to spawn a new copy of the shell that uses the upgraded environment and has access to the existing stdin, stdout and stderr, and does its reinitialization dance.

You need to do something like use subprocess.Popen to run /bin/bash -i.

So the original shell runs Python, which runs a new shell. Yes, you have a lot of processes running. No it's not too bad because the original shell and Python aren't really doing anything except waiting for the subshell to finish so they can exit cleanly, also.

Deleting an environmental variable for IIS

If you insist that you want to go with environmental variables (notice that you also have the alternative .env file), then you need to set them via the IIS FastCGI Settings from the IIS admin at server level for your specific application (the one you enabled via wfastcgi-enable).

Edit the specific row as said above and you'll find the Environment Variables collection under the "General" group of FastCGI Properties.

Now you can add and delete any of those variables and it will take effect immediately, without the need of any IIS reboot.

Deleting environment variables doesn't work

Here is the solution to my problem. I don't know if it is the correct solution, but it works for me:

Check variable.cmd

set TestVar

Set variable.cmd

setx TestVar 123

Delete variable.cmd

reg delete HKCU\Environment /F /V TestVar
setx DummyVarUsedToDelete ""
reg delete HKCU\Environment /F /V DummyVarUsedToDelete

setx cannot be used to delete a variable, as explained here, but it does the missing broadcasting after a variable has been removed from the registry with reg delete.


I added a line to delete the DummyVarUsedToDelete from the registry. This will not be broadcasted, but it is a small temporary problem.

How to save Env variable persistently

Used 'viper' lib to save env variables to the file:

func Getenv(key string) string {

err := viper.ReadInConfig()
if err != nil {
log.Fatalf("Error while reading config file %s", err)

value, ok := viper.Get(key).(string)
if !ok {
return ""

return value

func Setenv(key string, value string) {

err := viper.ReadInConfig()
if err != nil {
log.Fatalf("Error while reading config file %s", err)

viper.Set(key, value)

err = viper.WriteConfig()
if err != nil {
log.Fatalf("Error while writing config file %s", err)

Are they called environment or environmental variables?

Environment Variable

While environmental variable is used occasionally, environment variable is overwhelmingly more common:

  • Wikipedia: Environment Variable

  • Arch Linux wiki: Environment variables

    • "environment var" => 28 instances
    • "environmental var" => 3 instances
  • POSIX.1‐2017, Chapter 8. Environment Variables

  • Linux man pages:

    • environ(7) -- "Environment variables may be..."
    • getenv(3) -- "get an environment variable"
    • execve(2) -- just "environment"
    • bash(1) -- mostly just "environment", but occasionally "environment variable" and never "environmental"
  • Linux kernel

    • git grep -i 'environment var' | wc -l => 183
    • git grep -i 'environmental var' | wc -l => 2
  • MSDN

    • getenv() -- "Environment variable name"
    • GetEnvironmentVariable()
    • Environment.GetEnvironmentVariable()
  • Python

    • os module
  • Perl

    • Env -- "Perl maintains environment variables..."
  • Google

    • Searching for "get environmental variable" shows results for "get environment variable"
  • Stack Overflow

    • An environment-variables tag exists, but environmental-variables does not
    • There are 90,719 results for "environment variable" but only 4,345 results for "environmental variable"

Related Topics

Leave a reply