When using `getopts` with `case`: `*)` as the last pattern subclause, or `?)` and `:)` as the last two pattern subclauses?
Clash 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.
bash getopts
add a comment |Â
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.
bash getopts
add a comment |Â
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.
bash getopts
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.
bash getopts
edited Feb 25 at 16:16
asked Feb 25 at 16:08
Tim
22.7k64224401
22.7k64224401
add a comment |Â
add a comment |Â
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.
add a comment |Â
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.
add a comment |Â
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.
add a comment |Â
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.
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.
answered Feb 25 at 16:21
Kusalananda
103k13202318
103k13202318
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password