Closed jenstroeger closed 5 years ago
Ok… so here are more details. On a Mac, use
> /usr/bin/man /usr/share/man/man1/getopt.1
to get to the documentation of the original getopt
command from April 3, 1999
whose command line is simply as follows:
NAME
getopt -- parse command options
SYNOPSIS
args=`getopt optstring $*` ; errcode=$?; set -- $args
DESCRIPTION
The getopt utility is used to break up options in command lines for easy
parsing by shell procedures, and to check for legal options. Optstring
is a string of recognized option letters (see getopt(3)); if a letter is
followed by a colon, the option is expected to have an argument which may
or may not be separated from it by white space. The special option `--'
is used to delimit the end of the options. The getopt utility will place
`--' in the arguments at the end of the options, or recognize it if used
explicitly. The shell arguments ($1 $2 ...) are reset so that each
option is preceded by a `-' and in its own shell argument; each option
argument is also in its own shell argument.
The implication is that epubdate.sh
would lose the long options. Thus, adjusting the code according to the old documentation:
# Parse the options and arguments of this script.
OPTIONS=`GETOPT_COMPATIBLE="" getopt hbo:kt:a:i:p: -- $*`
set -- $OPTIONS
…
seems to work:
> ./epubdate.sh -h
Usage: epubdate.sh [OPTIONS] epub
…
I think it’s best to use the -T
option to perform a version check, and offer long options if the proper getopt
command is available and only short ones if it’s not.
Regarding this use of the getopt command:
https://github.com/jenstroeger/Bookalope/blob/10c2828b176bf84f268cac0b788cfd4fc5b18484/examples/epubdate.sh#L9-L10
MacOS 10.11.6 seems to ship with version
1.10 2002/09/04
or thereabouts, whereas the latest version seems to be from 2014 (link). This then causeswhich I can reproduce on my local Mac on Yosemite (10.14.5) as well when using
/usr/bin/getopt
directly.Not sure about the fix quite yet:
getopt
(inconvenient for users as updates would be required), or