Skip to content

Instantly share code, notes, and snippets.

@davidruhmann
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidruhmann/11293083 to your computer and use it in GitHub Desktop.
Save davidruhmann/11293083 to your computer and use it in GitHub Desktop.
[Batch] My Expand Routine
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: This works by exploiting the set and defined commands. If the Var is null,
:: then the set command will fail, the error message is caught, and the defined
:: command will fail because there should NEVER exist a variable named =.
:: Usage: call :Expand A %~1 0
:: The default works by exploiting how commands are parsed. If parameter 1 is
:: empty, then 0 will be passed to the routine as Value.
:: Author: David Ruhmann
:Expand <Var> [Value] [Default]
2>nul set "%~1=%~2"
if defined %~1 = exit /b 0
exit /b 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment