Link to home
Start Free TrialLog in
Avatar of Moshe072898
Moshe072898

asked on

How to "set" an empty environment variable?

I need to set an environment variable with an empty value. How do I do it ( in a batch file) ?
Avatar of jedimike
jedimike

if you set temp to nothing, it disappears.
Avatar of Moshe072898

ASKER

I know, I need to overcome this!
Avatar of dbrunton
Try this in Dos.  It may not be what you want

Set bill=gates

Set

and type set and you should see of course

bill=gates

Now

set bill=

(but prsss the spacebar after the equal sign before you press Enter)

and type set again and you will see

bill=

but of course bill is equal to the spacebar whick may not be what you want.
ASKER CERTIFIED SOLUTION
Avatar of j2
j2
Flag of Sweden image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
gah.. i meant that as a comment
Is it specified somewhere that a environment variable can not have an empty string value?
Yes, Every dos programmers manual since version 1.0 or so.
Lets reason here.

A enviroment variable can contain either "something" or "nothing" right?

When an enviroment variable contains "Nothing" it is removed from the enviroment.

Simple, huh? :)
Well, if the things are like that I don't see a way out here.
I am going to say that there is a way to do it.

Because the environment variable is removed we test for the environment variable.

Try the following batch file.

if "%temp%"=="C:\WINDOWS\TEMP" goto one
echo This is one
:one
if "%first%"==" " goto two
echo This is two
:two
if "%first%"=="" goto end
echo This is three
:end

If you do not have an envrionment variable set for first then you will not see the message This is three.
Ye, is's easy to define if a variable exists. But I need to PASS AN EMPTY STRING using an environment variable!