From: наб <nabijaczleweli@nabijaczleweli.xyz>
To: dash@vger.kernel.org
Subject: [PATCH] man: fix getopts documentation
Date: Wed, 14 Dec 2022 17:52:04 +0100 [thread overview]
Message-ID: <20221214165204.diohpccu6cx7nrdx@tarta.nabijaczleweli.xyz> (raw)
[-- Attachment #1: Type: text/plain, Size: 1725 bytes --]
The explicit arguments were missing, also exchange expr subst for
arithmetic and fix the spacing around Bell Labs
---
src/dash.1 | 13 +++++++++----
src/options.c | 2 +-
2 files changed, 10 insertions(+), 5 deletions(-)
diff --git a/src/dash.1 b/src/dash.1
index ff02237..46efd01 100644
--- a/src/dash.1
+++ b/src/dash.1
@@ -1342,13 +1342,12 @@ The number of previous commands that are accessible.
.El
.It fg Op Ar job
Move the specified job or the current job to the foreground.
-.It getopts Ar optstring var
+.It getopts Ar optstring var Op Ar arg ...
The
.Tn POSIX
.Ic getopts
command, not to be confused with the
-.Em Bell Labs
--derived
+.Em Bell Labs Ns -derived
.Xr getopt 1 .
.Pp
The first argument should be a series of letters, each of which may be
@@ -1386,6 +1385,12 @@ then
.Ev OPTARG
will be unset.
.Pp
+By default, the variables
+.Va $1 , ... , $n
+are inspected; if
+.Ar arg Ns s
+are specified, they'll be parsed instead.
+.Pp
.Va optstring
is a string of recognized option letters (see
.Xr getopt 3 ) .
@@ -1430,7 +1435,7 @@ do
\\?) echo $USAGE; exit 1;;
esac
done
-shift `expr $OPTIND - 1`
+shift $((OPTIND - 1))
.Ed
.Pp
This code will accept any of the following as equivalent:
diff --git a/src/options.c b/src/options.c
index a46c23b..3158498 100644
--- a/src/options.c
+++ b/src/options.c
@@ -410,7 +410,7 @@ getoptscmd(int argc, char **argv)
char **optbase;
if (argc < 3)
- sh_error("Usage: getopts optstring var [arg]");
+ sh_error("Usage: getopts optstring var [arg...]");
else if (argc == 3) {
optbase = shellparam.p;
if ((unsigned)shellparam.optind > shellparam.nparam + 1) {
--
2.30.2
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next reply other threads:[~2022-12-14 16:52 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-14 16:52 наб [this message]
2023-01-05 9:44 ` [PATCH] man: fix getopts documentation Herbert Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221214165204.diohpccu6cx7nrdx@tarta.nabijaczleweli.xyz \
--to=nabijaczleweli@nabijaczleweli.xyz \
--cc=dash@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.