[PATCH] man: fix getopts documentation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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: signature.asc
Description: PGP signature


[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux