diff mbox series

man: fix getopts documentation

Message ID 20221214165204.diohpccu6cx7nrdx@tarta.nabijaczleweli.xyz (mailing list archive)
State Accepted
Delegated to: Herbert Xu
Headers show
Series man: fix getopts documentation | expand

Commit Message

наб Dec. 14, 2022, 4:52 p.m. UTC
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(-)

Comments

Herbert Xu Jan. 5, 2023, 9:44 a.m. UTC | #1
наб <nabijaczleweli@nabijaczleweli.xyz> wrote:
> [-- text/plain, encoding quoted-printable, charset: us-ascii, 65 lines --]
> 
> 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(-)

Patch applied.  Thanks.
diff mbox series

Patch

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) {