Created
December 7, 2012 17:00
-
-
Save davidruhmann/4234677 to your computer and use it in GitHub Desktop.
[Batch] Detect if a variable name is defined with a value.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:: Determine if a Variable name is defined with a value. | |
:: by David Ruhmann | |
:: Hide Commands | |
@echo off | |
setlocal ENABLEEXTENSIONS | |
:: Example Usage | |
set "xVar=Value" | |
call :IsDefined xResult xVar | |
if "%xResult%"=="true" echo.Defined | |
set "xVar=" | |
call :IsDefined xResult xVar | |
if not "%xResult%"=="true" echo.Undefined | |
pause | |
goto End | |
:End | |
endlocal | |
:: by David Ruhmann |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
:IsDefined <xResult> <xInput> | |
:: Verify if a variable is defined, return true if defined. | |
:::: Made as an alternative to DEFINED, both methods require ENABLEEXTENSIONS. | |
if not "%~1"=="" set "%~1=false" | |
for /f "usebackq tokens=1,2* delims==" %%a in (`set`) do if "%~2"=="%%~a" if not "%~1"=="" set "%~1=true" | |
goto :eof | |
:: by David Ruhmann |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment