Using parameters in batch files at Windows command line.
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
@echo off | |
:: parse.bat --foo --bar | |
:: parse.bat --foo --bar --param 1 | |
:: parse.bat --foo --bar --param2 5 | |
:: parse.bat --foo --bar --param2 5 --param 100 | |
:: parse.bat --foo --bar --param 1 --param2 5 | |
setlocal | |
:parse | |
if "%~1"=="" GOTO endparse | |
if "%~1"=="--foo" (set _FOO=true) | |
if "%~1"=="--bar" (set _BAR=true) | |
if "%~1"=="--param" (set _PARAM=%~2) | |
if "%~1"=="--param2" (set _PARAM2=%~2) | |
shift | |
GOTO parse | |
:endparse | |
:: debug | |
if "%_FOO%"=="true" echo --foo detected | |
if "%_BAR%"=="true" echo --bar detected | |
if not "%_PARAM%"=="" echo --param %_PARAM% | |
if not "%_PARAM2%"=="" echo --param2 %_PARAM2% | |
endlocal |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Equivalent to following bash script.