In Bash, we can set an environment variable for a single command this way:
FOO=bar somecommand
What if we want to unset a variable for a single command?
To unset an environment variable from Command Prompt, type the command setx variable_name “”. For example, we typed setx TEST “” and this environment variable now had an empty value.
We can set variables for a single command using this syntax: VAR1=VALUE1 VAR2=VALUE2 ... Command ARG1 ARG2...
To unset the variable simply set the value of variable to '' . c.) Here, we created a local variable VAR2 and set it to a value. Then in-order to run a command temporarily clearing out all local and other environment variables, we executed 'env –i' command.
The dsadmin command can be used for deleting an environment variable in a particular project.
Technically, they're not environment variables until someone export
s them. But you can at least set them to empty:
FOO= some command
If removing them from the environment is enough, you can use env
:
env -u FOO somecommand
env -u FOO somecommand
This will remove the environment variable FOO
from the somecommand
process' environment.
And to unset multiple variables:
env -u FOO -u FOO2 somecommand
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With