*NIX getopt alike for DOS











up vote
0
down vote

favorite












I want to write a DOS script with multiple optional option flags. I have to parse these optional options.



An example:



get_resolution.bat /?
get_resolution.bat /h input.jpg
get_resoltion.bat /v input.jpg


Under *NIX this can be done with getopts.



The same examples under *nix:



get_resolution -?
get_resolution -h input.jpg
get_resolution -v input.jpg


In the *nix script txt file get_resolution one would then write:



while getopts ?hv flag  
do
case $flag in
?) man get_resolution
h) get_horizontal_resolution $1
v) get_vertical_resolution $1 ;;
esac
done


Does there exist a DOS equivalent for the *nix getopts?










share|improve this question




















  • 2




    You’re most certainly not talking about DOS. Please read the tag descriptions carefully and edit your question accordingly.
    – Daniel B
    Nov 17 at 18:45















up vote
0
down vote

favorite












I want to write a DOS script with multiple optional option flags. I have to parse these optional options.



An example:



get_resolution.bat /?
get_resolution.bat /h input.jpg
get_resoltion.bat /v input.jpg


Under *NIX this can be done with getopts.



The same examples under *nix:



get_resolution -?
get_resolution -h input.jpg
get_resolution -v input.jpg


In the *nix script txt file get_resolution one would then write:



while getopts ?hv flag  
do
case $flag in
?) man get_resolution
h) get_horizontal_resolution $1
v) get_vertical_resolution $1 ;;
esac
done


Does there exist a DOS equivalent for the *nix getopts?










share|improve this question




















  • 2




    You’re most certainly not talking about DOS. Please read the tag descriptions carefully and edit your question accordingly.
    – Daniel B
    Nov 17 at 18:45













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I want to write a DOS script with multiple optional option flags. I have to parse these optional options.



An example:



get_resolution.bat /?
get_resolution.bat /h input.jpg
get_resoltion.bat /v input.jpg


Under *NIX this can be done with getopts.



The same examples under *nix:



get_resolution -?
get_resolution -h input.jpg
get_resolution -v input.jpg


In the *nix script txt file get_resolution one would then write:



while getopts ?hv flag  
do
case $flag in
?) man get_resolution
h) get_horizontal_resolution $1
v) get_vertical_resolution $1 ;;
esac
done


Does there exist a DOS equivalent for the *nix getopts?










share|improve this question















I want to write a DOS script with multiple optional option flags. I have to parse these optional options.



An example:



get_resolution.bat /?
get_resolution.bat /h input.jpg
get_resoltion.bat /v input.jpg


Under *NIX this can be done with getopts.



The same examples under *nix:



get_resolution -?
get_resolution -h input.jpg
get_resolution -v input.jpg


In the *nix script txt file get_resolution one would then write:



while getopts ?hv flag  
do
case $flag in
?) man get_resolution
h) get_horizontal_resolution $1
v) get_vertical_resolution $1 ;;
esac
done


Does there exist a DOS equivalent for the *nix getopts?







windows-10 batch ms-dos






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 17 at 19:38

























asked Nov 17 at 18:27









Francky Leyn

324




324








  • 2




    You’re most certainly not talking about DOS. Please read the tag descriptions carefully and edit your question accordingly.
    – Daniel B
    Nov 17 at 18:45














  • 2




    You’re most certainly not talking about DOS. Please read the tag descriptions carefully and edit your question accordingly.
    – Daniel B
    Nov 17 at 18:45








2




2




You’re most certainly not talking about DOS. Please read the tag descriptions carefully and edit your question accordingly.
– Daniel B
Nov 17 at 18:45




You’re most certainly not talking about DOS. Please read the tag descriptions carefully and edit your question accordingly.
– Daniel B
Nov 17 at 18:45










1 Answer
1






active

oldest

votes

















up vote
1
down vote













In batch scripts all arguments are stored in variable %*. Each argument can accessed by variable %1 for the first argument, and %2 for the second and so on. You can handle the arguments like this until %9.



More elegant argument handling requires the use of shift-command.



Take a look this Stackoverflow question: https://stackoverflow.com/questions/14286457/using-parameters-in-batch-files-at-windows-command-line



It has more information about handling arguments in batch scripts.






share|improve this answer























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "3"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1376284%2fnix-getopt-alike-for-dos%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    In batch scripts all arguments are stored in variable %*. Each argument can accessed by variable %1 for the first argument, and %2 for the second and so on. You can handle the arguments like this until %9.



    More elegant argument handling requires the use of shift-command.



    Take a look this Stackoverflow question: https://stackoverflow.com/questions/14286457/using-parameters-in-batch-files-at-windows-command-line



    It has more information about handling arguments in batch scripts.






    share|improve this answer



























      up vote
      1
      down vote













      In batch scripts all arguments are stored in variable %*. Each argument can accessed by variable %1 for the first argument, and %2 for the second and so on. You can handle the arguments like this until %9.



      More elegant argument handling requires the use of shift-command.



      Take a look this Stackoverflow question: https://stackoverflow.com/questions/14286457/using-parameters-in-batch-files-at-windows-command-line



      It has more information about handling arguments in batch scripts.






      share|improve this answer

























        up vote
        1
        down vote










        up vote
        1
        down vote









        In batch scripts all arguments are stored in variable %*. Each argument can accessed by variable %1 for the first argument, and %2 for the second and so on. You can handle the arguments like this until %9.



        More elegant argument handling requires the use of shift-command.



        Take a look this Stackoverflow question: https://stackoverflow.com/questions/14286457/using-parameters-in-batch-files-at-windows-command-line



        It has more information about handling arguments in batch scripts.






        share|improve this answer














        In batch scripts all arguments are stored in variable %*. Each argument can accessed by variable %1 for the first argument, and %2 for the second and so on. You can handle the arguments like this until %9.



        More elegant argument handling requires the use of shift-command.



        Take a look this Stackoverflow question: https://stackoverflow.com/questions/14286457/using-parameters-in-batch-files-at-windows-command-line



        It has more information about handling arguments in batch scripts.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 17 at 20:10

























        answered Nov 17 at 19:51









        Aulis Ronkainen

        6151514




        6151514






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1376284%2fnix-getopt-alike-for-dos%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Сан-Квентин

            8-я гвардейская общевойсковая армия

            Алькесар