Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #11877

Re: Possible bug in getopts when required argument is not supplied

From "Griff Miller II" <griff.miller@oplink.net>
Newsgroups gnu.bash.bug
Subject Re: Possible bug in getopts when required argument is not supplied
Date 2015-11-13 13:54 -0600
Message-ID <mailman.2284.1447444490.7904.bug-bash@gnu.org> (permalink)
References <535058272b68c9459882c6bd4565b428.squirrel@webmail.oplink.net> <CANaoh6K=OB7YAeFftc=a3ypYTz0jHPBjCok0KqR=a9pi2-pDPw@mail.gmail.com>

Show all headers | View raw


On Fri, November 13, 2015 1:02 pm, Dennis Williamson wrote:
> Your opts string needs to begin with a colon to enable silent error
> reporting and you need to handle the colon in your case statement as the
> condition where a required argument is missing.

Hi, Dennis - thanks for replying. I get the same behavior with silent
reporting. My real script where I discovered this behavior actually uses
silent reporting - I didn't use it in my example to keep things simple.

> Snippets:
>
>
> opts=:a:b:c
>
>
> :) echo "Missing argument for option -$OPTARG" >&2;;
>
>
> You should escape the question mark since otherwise it's a globbing
> character:

You are right! I missed that when throwing together my example script.

> \?) echo "Unknown option: -$OPTARG" >&2; exit 1;;
>
>
> --
> Visit serverfault.com to get your system administration questions
> answered.
>


Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

Re: Possible bug in getopts when required argument is not supplied "Griff Miller II" <griff.miller@oplink.net> - 2015-11-13 13:54 -0600

csiph-web