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

前端 未结 9 1720
情话喂你
情话喂你 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:10

    Other way I quite liked:

    set c=defaultC
    set s=defaultS
    set u=defaultU
    
    :initial
    if "%1"=="" goto done
    echo              %1
    set aux=%1
    if "%aux:~0,1%"=="-" (
       set nome=%aux:~1,250%
    ) else (
       set "%nome%=%1"
       set nome=
    )
    shift
    goto initial
    :done
    
    echo %c%
    echo %s%
    echo %u%
    

    Run the following command:

    arguments.bat -c users -u products
    

    Will generate the following output:

    users
    defaultS
    products
    

提交回复
热议问题