diff options
author | наб <nabijaczleweli@nabijaczleweli.xyz> | 2022-12-14 17:52:04 +0100 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2023-01-05 17:41:20 +0800 |
commit | 5c55b53f2b028228837f712b3c3e13363c3310e4 (patch) | |
tree | db40d3d4bc35af5f04d50947a2e766537ab0e042 | |
parent | 8dbbff647de1e3a1510866fa1ec983c3b88f432c (diff) | |
download | dash-5c55b53f2b028228837f712b3c3e13363c3310e4.tar.gz |
man: Fix getopts documentation
The explicit arguments were missing, also exchange expr subst for
arithmetic and fix the spacing around Bell Labs
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r-- | src/dash.1 | 13 | ||||
-rw-r--r-- | src/options.c | 2 |
2 files changed, 10 insertions, 5 deletions
@@ -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) { |