Looking for Unix style 'getopt' command line parsing in a Windows batch file

前端 未结 2 1048
后悔当初
后悔当初 2020-12-19 12:27

Can anyone help me find something to parse command line args in a Windows batch file like one would do in a Unix shell script using getopt/getopts? It doesn\'t have to be a

2条回答
  •  长情又很酷
    2020-12-19 13:14

    There is no such thing as getopt/getopts-like parsing of commandline arguments as you know from Unix/Linux.

    Batch files only know about %0, %1, %2, ... and %* (and such variations as %~0, %~1... which remove quotes, should there be ones around an arg).

    Up to nine arguments. If there are more to process, you can use shift (equiv. to shift /1 if enableextensions happened) to remove the first arg and shift the rest.

    Basically that's it.


    (Maybe you should explain more what exactly you are trying to achieve with the batch, why you must use batch, and what your other external constraints are.)

提交回复
热议问题