How to? Correctly use defined test

  • This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.
Jun 11, 2008
26
0
#1
Hi

I recently tried to (unsuccessfully) to use "defined" like this:
Code:
setlocal
set var=%1

iff defined %var then
echo var defined as %var
else
echo var not defined
endiff

echo.
echo end defined test
This code always returns "var not defined". My expectation was that it should behave the same as if I had used "iff !%var! != !! then". What have I misunderstood about using defined?

John
 
Jun 11, 2008
26
0
#3
Don't use the % in front of the variable name. (You were testing whether the contents of %var was an environment variable, not whether "var" was a defined variable.)
Thanks Rex, "var" is name of variable "%var" is content of var.

John