It seems to be bug in some versions of the program.
It works for me in in Centos 7.3 and Fedora 19
[vps1 ~]$ cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
[vps1 ~]$ getopt --name xyz --options "xyz:" -- -x -z
xyz: option requires an argument -- 'z'
-x --
[vps1 ~]$ getopt -V
getopt from util-linux 2.23.2
But it doesn't in my MinGW shell (from Git for Windows)
$ getopt --name xyz --options "xyz:" -- -x -z
getopt: option requires an argument -- z
-x --
$ getopt -V
getopt from util-linux 2.26.2
Update: It works also in 2.27.1 in Linux. And it doesn't work in (at least some version of) Cygwin. So the problem seems to be in the Windows ports (both Mingw and Cygwin, interestingly).
I'll throw a wild guess (not big probability of hitting the target):
The getopt
program, since this commit tries to deal with some environnments (in particular, BSD; not Linux) that have/use the getprogname/setprogname
to get/set the "current" program name (instead of relying on argv[0]
).
#if defined (HAVE_SETPROGNAME) && !defined (__linux__)
setprogname(name);
Now, let's imagine that
- Cygwin and MinGW/Msis both support those functions.
- However, they lack the
HAVE_SETPROGNAME
define
- Further, their
getopt
functions (mind you, not the program), just like the BSD version, use getprogname
instead of argv[0]
In that case, the problem would be explained. However, I'm skeptical - of point 3 especially.