The documented behaviour of GNU getopt()
is to stop at the first non-option argument only when in POSIX mode, which can be set via a +
at the start of the option string or by setting the POSIXLY_CORRECT
environment variable.
In its default mode, GNU getopt()
'permutes the contents of argv
as it scans, so eventually all the non-options are at the end.'
You are hitting this difference in the behaviour — it is the difference between GNU getopt()
and BSD getopt()
behaviour, because the BSD getopt()
has POSIX semantics.