OMG I've never seen a use for that option before. I saw Disable and just assumed DelayedExpansion.jeb wrote:The setlocal DisableExtensions is the key
I see it working now (from home), thanks.
I just discovered that =:: is NOT defined on my Vista 32bit machine at work It is defined on Vista 64bit at home.
jeb wrote:dBenham wrote:Just an observation - It seems very odd that normal dynamic variables (ERRORLEVEL, TIME, RANDOM etc) never show up in SET command, but do test as defined (IF DEFINED ERRORLEVEL is true). But the = dynamic variables do show up in SET "" command, but test as undefined (IF DEFINED =C: is false)
I didn't know if it is "defined", as I didn't know how to test it, in your case you only test if "C:" is defined, with echo on you will seeif defined C: (echo exist ) ELSE echo not defined
It took a while, but I'm finally catching on. I had noticed in the past how ECHO ON output does not match the source code, but only now am I realizing how useful it can be for understanding parsing, escaping, etc. issues.
I've discovered how to successfully test if an = variable is defined. There is a parsing problem in phase 2 concerning the =, and some special IF parsing rule prevents us from escaping the = properly. Yes The problem is solved by using a FOR variable or delayed expansion of a normal variable.
Code: Select all
@echo off
setlocal enableDelayedExpansion
prompt $g
echo on
:: direct test does not work, and escaping doesn't help
if defined =c: (echo =c: is defined) else echo =c: is not defined
if defined ^=c: (echo =c: is defined) else echo =c: is not defined
if defined ^^=c: (echo =c: is defined) else echo =c: is not defined
if defined ^^^=c: (echo =c: is defined) else echo =c: is not defined
:: for variable and delayed expansion bypass parsing problem in phase 2
@set var==c:
for /f %%v in ("!var!") do if defined %%v (echo %%v is defined) else echo %%v is not defined
if defined !var! (echo !var! is defined) else echo !var! is not defined
Output:
Code: Select all
>if defined c: (echo =c: is defined ) else echo =c: is not defined
=c: is not defined
>if defined c: (echo =c: is defined ) else echo =c: is not defined
=c: is not defined
>if defined ^ c: (echo =c: is defined) else echo =c: is not defined
>if defined ^ (echo =c: is defined ) else echo =c: is not defined
=c: is not defined
>for /F %v in ("!var!") do if defined %v (echo %v is defined ) else echo %v is not defined
>if defined =c: (echo =c: is defined ) else echo =c: is not defined
=c: is defined
>if defined !var! (echo !var! is defined ) else echo !var! is not defined
=c: is defined
Dave Benham