1

Is that a long option can be shortened arbitrarily part of GNU conventions for options, or some other conventions/standards, or just provided by some special C function?

For example, why do python and awk behave differently?

$ python --version
Python 2.7.12
$ python --versio
Unknown option: --
usage: python [option] ... [-c cmd | -m mod | file | -] [arg] ...
Try `python -h' for more information.

$ awk --version
GNU Awk 4.1.3, API: 1.1 (GNU MPFR 3.1.4, GNU MP 6.1.0)
$ awk --versi
GNU Awk 4.1.3, API: 1.1 (GNU MPFR 3.1.4, GNU MP 6.1.0)

Thanks.

Stephen Kitt
  • 434,908
Tim
  • 101,790
  • 1
    See also https://unix.stackexchange.com/questions/289191/abbreviated-long-options-on-the-command-line-of-xclip – derobert Jul 21 '17 at 17:32

1 Answers1

6

It's a feature of GNU libc, from the getopt_long manpage:

Long option names may be abbreviated if the abbreviation is unique or is an exact match for some defined option.

Similarly, GNU libc's Argp interface also allows abbreviated options (though it's possible to reject them, if a program really cares).

As noted in Abbreviated long options on the command line of xclip, xlib does the same thing, so xclock -dig -bri is the same as xclock -digital -brief.

I wouldn't recommend doing this in scripts: your awk --ver call be ambiguous if they added awk --verbose.

Python presumably has written its own argument parser, likely to be portable to systems which don't use glibc. And they can't just borrow the glibc one because they're not using the GNU GPL license.

derobert
  • 109,670