0

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.

5

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.