Batch nested If statement error with not defined variables -


i have problem simple batch script. see:

set test= if not defined test (      set "test=1" ) else (     if %test% lss 1 ( set "test=1") ) 

here if in else branch failes, because variable test ist not defined. else branch shouldn't been executed if variable test isn't defined!? here problem? (i knew, code work, if leave else , write under if statement, code get's executed every time.) how solve problem?

thx.

magoo's answer prevent error lead alphabetical comparison instead of numerical.i think better use delayed expansion , 1 additional if defined statement :

setlocal enabledelayedexpansion set "test=" if not defined test (      set "test=1" ) else (     if defined test if !test! lss 1 ( set "test=1") ) 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -