[PATCH 10/17] getopt.3: Clarify behaviour

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

 



From: "James O. D. Hunt" <jamesodhunt@xxxxxxxxx>

Improved the `getopt(3)` man page in the following ways:

1) Defined the existing term "legitimate option character".
2) Added an additional NOTE stressing that arguments are parsed in strict
   order and the implications of this when numeric options are utilised.

Signed-off-by: James O. D. Hunt <jamesodhunt@xxxxxxxxx>
Signed-off-by: Alejandro Colomar <alx.manpages@xxxxxxxxx>
---
 man3/getopt.3 | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/man3/getopt.3 b/man3/getopt.3
index 921e747f8..e88321ed0 100644
--- a/man3/getopt.3
+++ b/man3/getopt.3
@@ -126,6 +126,11 @@ Then \fIoptind\fP is the index in \fIargv\fP of the first
 .PP
 .I optstring
 is a string containing the legitimate option characters.
+A legitimate option character is any visible one byte
+.BR ascii (7)
+character (for which
+.BR isgraph (3)
+would return nonzero) that is not dash (\(aq\-\(aq) or colon (\(aq:\(aq).
 If such a
 character is followed by a colon, the option requires an argument, so
 .BR getopt ()
@@ -402,6 +407,24 @@ routine that rechecks
 .B POSIXLY_CORRECT
 and checks for GNU extensions in
 .IR optstring .)
+.PP
+Command-line arguments are parsed in strict order
+meaning that an option requiring an argument will consume the next argument,
+regardless of whether that argument is the correctly specified option argument
+or simply the next option
+(in the scenario the user mis-specifies the command line).
+For example, if
+.I optstring
+is specified as "1n:"
+and the user specifies the command line arguments incorrectly as
+.IR "prog\ \-n\ \-1" ,
+the
+.I \-n
+option will be given the
+.B optarg
+value "\-1", and the
+.I \-1
+option will be considered to have not been specified.
 .SH EXAMPLES
 .SS getopt()
 The following trivial example program uses
-- 
2.31.1




[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux