Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I remove a cmd variable?

Tags:

batch-file

cmd

Let's say I execute the following in the CMD shell:

SET "FOO=bar" 

Is there a way to undefine this variable, other than recycling the CMD shell?

like image 898
user288004 Avatar asked Aug 28 '11 07:08

user288004


People also ask

Which command is used to delete variable?

The drop command is used to remove variables or observations from the dataset in memory. If you want to drop variables, use drop varlist. If you want to drop observations, use drop with an if or an in qualifier or both.

How do you delete an environment variable?

Delete Environment Variables You need to just use the unset command with the variable name to delete it. This command will remove the variable permanently.


2 Answers

Yes, you can unset it with

set FOO= 

Or explicitly using:

set "FOO=" 

Ensure no trailing extraneous (invisible) characters come after the = sign. That is:

  • set FOO= is different from set FOO=      .
like image 111
Madara's Ghost Avatar answered Oct 07 '22 01:10

Madara's Ghost


A secure way to unset the variable is to use also quotes, then there aren't problems with trailing spaces.

set FOO=bar echo %FOO% set "FOO=" text after the last quote is ignored echo %FOO% 
like image 40
jeb Avatar answered Oct 07 '22 01:10

jeb