Is there a way to pass parameters “by name” (and not by order) to a batch .bat file?

前端 未结 9 1737
情话喂你
情话喂你 2021-01-30 20:35

I need to be able to pass parameters to a windows batch file BY NAME (and NOT by order). My purpose here is to give end user the flexibility to pass parameters in any order, and

9条回答
  •  时光取名叫无心
    2021-01-30 21:04

    :parse
    IF "%~1"=="" GOTO endparse
    ECHO "%~1"| FIND /I "=" && SET "%~1"
    SHIFT /1
    GOTO parse
    :endparse
    

    This code checks all the parameters, strips all the outer quotes, and if equal sign is present, sets variable to value.

    Use it like this:

    yourbatch.bat "foo=bar" "foo2=bar2"
    

    based on this answer: Using parameters in batch files at DOS command line, and edited in response to the edit attempt by D.Barev

提交回复
热议问题