How do I delete an exported environment variable?
unset
is the command you're looking for.
unset GNUPLOT_DRIVER_DIR
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
@pause
Set variable.cmd
setx TestVar 123
@pause
Delete variable.cmd
reg delete HKCU\Environment /F /V TestVar
setx DummyVarUsedToDelete ""
reg delete HKCU\Environment /F /V DummyVarUsedToDelete
@pause
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
.
EDIT
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 {
viper.SetConfigType("env")
viper.SetConfigFile(".env")
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) {
viper.SetConfigType("env")
viper.SetConfigFile(".env")
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
(title)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
=> 183git 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
Stack Overflow
- An
environment-variables
tag exists, butenvironmental-variables
does not - There are 90,719 results for "environment variable" but only 4,345 results for "environmental variable"
- An
Related Topics
Free Git Server With Web Gui a La Bitbucket/Github
Extract File Basename Without Path and Extension in Bash
How to Find Out What All Symbols Are Exported from a Shared Object
How to Create a Crontab Through a Script
How to Change the Default Browser Used by the Ipython/Jupyter Notebook in Linux
Compiling C++ on Remote Linux Machine - "Clock Skew Detected" Warning
How Is the System Call in Linux Implemented
Bash Prompt With the Last Exit Code
How to Randomize the Lines in a File Using Standard Tools on Red Hat Linux
How to Manage Perl Modules When Using a Package Manager
How to Print a Character in Linux X86 Nasm
How to Run a Shell Script on a Unix Console or MAC Terminal
How to Fix Java.Lang.Module.Findexception: Module Java.Se.Ee Not Found
Understanding User File Ownership in Docker: How to Avoid Changing Permissions of Linked Volumes