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) ?
if you set temp to nothing, it disappears.
ASKER
I know, I need to overcome this!
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
gah.. i meant that as a comment
ASKER
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? :)
A enviroment variable can contain either "something" or "nothing" right?
When an enviroment variable contains "Nothing" it is removed from the enviroment.
Simple, huh? :)
ASKER
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.
Because the environment variable is removed we test for the environment variable.
Try the following batch file.
if "%temp%"=="C:\WINDOWS\TEMP
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.
ASKER
Ye, is's easy to define if a variable exists. But I need to PASS AN EMPTY STRING using an environment variable!