When using `getopts` with `case`: `*)` as the last pattern subclause, or `?)` and `:)` as the last two pattern subclauses?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












When using getopts with case clause, is a *) pattern subclause as the last pattern subclause equivalent to the union of ?) and :) pattern subclauses as the last two pattern subclauses? Specifically,



while getopts "<optionString>" opt; do
case $opt in
a) a="$OPTARG"
;;
b) b="$OPTARG"
;;

...
;;

?) printf "illegal option: -%sn" "$OPTARG" >&2
exit 1
;;
:) printf "missing argument for -%sn" "$OPTARG" >&2
exit 1
;;
esac
done


and



while getopts "<optionString>" opt; do
case $opt in
a) a="$OPTARG"
;;
b) b="$OPTARG"
;;

...
;;

*) printf "illegal option: -%s, or missing argument for -%sn" "$OPTARG" "$OPTARG" >&2
exit 1
;;
esac
done


Thanks.







share|improve this question


























    up vote
    0
    down vote

    favorite












    When using getopts with case clause, is a *) pattern subclause as the last pattern subclause equivalent to the union of ?) and :) pattern subclauses as the last two pattern subclauses? Specifically,



    while getopts "<optionString>" opt; do
    case $opt in
    a) a="$OPTARG"
    ;;
    b) b="$OPTARG"
    ;;

    ...
    ;;

    ?) printf "illegal option: -%sn" "$OPTARG" >&2
    exit 1
    ;;
    :) printf "missing argument for -%sn" "$OPTARG" >&2
    exit 1
    ;;
    esac
    done


    and



    while getopts "<optionString>" opt; do
    case $opt in
    a) a="$OPTARG"
    ;;
    b) b="$OPTARG"
    ;;

    ...
    ;;

    *) printf "illegal option: -%s, or missing argument for -%sn" "$OPTARG" "$OPTARG" >&2
    exit 1
    ;;
    esac
    done


    Thanks.







    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      When using getopts with case clause, is a *) pattern subclause as the last pattern subclause equivalent to the union of ?) and :) pattern subclauses as the last two pattern subclauses? Specifically,



      while getopts "<optionString>" opt; do
      case $opt in
      a) a="$OPTARG"
      ;;
      b) b="$OPTARG"
      ;;

      ...
      ;;

      ?) printf "illegal option: -%sn" "$OPTARG" >&2
      exit 1
      ;;
      :) printf "missing argument for -%sn" "$OPTARG" >&2
      exit 1
      ;;
      esac
      done


      and



      while getopts "<optionString>" opt; do
      case $opt in
      a) a="$OPTARG"
      ;;
      b) b="$OPTARG"
      ;;

      ...
      ;;

      *) printf "illegal option: -%s, or missing argument for -%sn" "$OPTARG" "$OPTARG" >&2
      exit 1
      ;;
      esac
      done


      Thanks.







      share|improve this question














      When using getopts with case clause, is a *) pattern subclause as the last pattern subclause equivalent to the union of ?) and :) pattern subclauses as the last two pattern subclauses? Specifically,



      while getopts "<optionString>" opt; do
      case $opt in
      a) a="$OPTARG"
      ;;
      b) b="$OPTARG"
      ;;

      ...
      ;;

      ?) printf "illegal option: -%sn" "$OPTARG" >&2
      exit 1
      ;;
      :) printf "missing argument for -%sn" "$OPTARG" >&2
      exit 1
      ;;
      esac
      done


      and



      while getopts "<optionString>" opt; do
      case $opt in
      a) a="$OPTARG"
      ;;
      b) b="$OPTARG"
      ;;

      ...
      ;;

      *) printf "illegal option: -%s, or missing argument for -%sn" "$OPTARG" "$OPTARG" >&2
      exit 1
      ;;
      esac
      done


      Thanks.









      share|improve this question













      share|improve this question




      share|improve this question








      edited Feb 25 at 16:16

























      asked Feb 25 at 16:08









      Tim

      22.7k64224401




      22.7k64224401




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          You only really need to check for : and ? with the getopts in bash if you use silent error reporting (when the first character of the optstring is a colon).



          When getopts in not used in that way, it will produce its own diagnostic messages for invalid options and for missing option arguments (and these are usually quite adequate). In fact, it will not place : or ? in the variable unless it's silenced.



          Using * in a case statement would be a way to catch both of these, but if getopts is silenced, you would not know which error was triggered and would just be able to say something on the lines of an error occurred while parsing the command line options to the user.






          share|improve this answer




















            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "106"
            ;
            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: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );








             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f426482%2fwhen-using-getopts-with-case-as-the-last-pattern-subclause-or-a%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            1
            down vote



            accepted










            You only really need to check for : and ? with the getopts in bash if you use silent error reporting (when the first character of the optstring is a colon).



            When getopts in not used in that way, it will produce its own diagnostic messages for invalid options and for missing option arguments (and these are usually quite adequate). In fact, it will not place : or ? in the variable unless it's silenced.



            Using * in a case statement would be a way to catch both of these, but if getopts is silenced, you would not know which error was triggered and would just be able to say something on the lines of an error occurred while parsing the command line options to the user.






            share|improve this answer
























              up vote
              1
              down vote



              accepted










              You only really need to check for : and ? with the getopts in bash if you use silent error reporting (when the first character of the optstring is a colon).



              When getopts in not used in that way, it will produce its own diagnostic messages for invalid options and for missing option arguments (and these are usually quite adequate). In fact, it will not place : or ? in the variable unless it's silenced.



              Using * in a case statement would be a way to catch both of these, but if getopts is silenced, you would not know which error was triggered and would just be able to say something on the lines of an error occurred while parsing the command line options to the user.






              share|improve this answer






















                up vote
                1
                down vote



                accepted







                up vote
                1
                down vote



                accepted






                You only really need to check for : and ? with the getopts in bash if you use silent error reporting (when the first character of the optstring is a colon).



                When getopts in not used in that way, it will produce its own diagnostic messages for invalid options and for missing option arguments (and these are usually quite adequate). In fact, it will not place : or ? in the variable unless it's silenced.



                Using * in a case statement would be a way to catch both of these, but if getopts is silenced, you would not know which error was triggered and would just be able to say something on the lines of an error occurred while parsing the command line options to the user.






                share|improve this answer












                You only really need to check for : and ? with the getopts in bash if you use silent error reporting (when the first character of the optstring is a colon).



                When getopts in not used in that way, it will produce its own diagnostic messages for invalid options and for missing option arguments (and these are usually quite adequate). In fact, it will not place : or ? in the variable unless it's silenced.



                Using * in a case statement would be a way to catch both of these, but if getopts is silenced, you would not know which error was triggered and would just be able to say something on the lines of an error occurred while parsing the command line options to the user.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Feb 25 at 16:21









                Kusalananda

                103k13202318




                103k13202318






















                     

                    draft saved


                    draft discarded


























                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f426482%2fwhen-using-getopts-with-case-as-the-last-pattern-subclause-or-a%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Popular posts from this blog

                    How to check contact read email or not when send email to Individual?

                    Bahrain

                    Postfix configuration issue with fips on centos 7; mailgun relay