POSIX conventions and GNU Long Options

Source: Internet
Author: User
Tags arabic numbers
POSIX standard clockProgramConventions on names, options, and parameters:

  1. The program name should be no less than 2 Characters and no more than 9 Characters
  2. The program name should only contain lowercase letters and Arabic numbers
  3. The option name should be a single letter or a single digit, and the multi-digit option should not be allowed. -W option reserved for dedicated suppliers
  4. All options should start '-'
  5. For those options that do not require parameters, it is possible to aggregate the options after multiple '-' (for example, 'foo-a-B-C' and 'foo-abc' should be handled in the same way)
  6. When a parameter is required for an option, the parameter and option should be separated by spaces (for example, 'fgrep-F patfile '). However, POSIX standards take into account past practices. Sometimes options and operands can be in the same string: 'fgrep-fpatfile '. In fact, the getopt () and getopt_long () functions interpret '-fpatfile' as'-F patfile' instead of '-F-p-a-t ...'
  7. Option parameters should not be optional
  8. If the option accepts multiple values, the program shouldAs a stringReceived. The values in the string are separated by commas (,) or blank characters. For example, myprog-U "Arnold, Joe, Jane" (separated by commas); myprog-U "Arnold Joe Jane" (separated by blank characters)
  9. The option should appear on the command line before the operand. The getopt () force option of the UNIX version complies with this Convention. The getopt () of the GNU version does not have this Convention by default, but you can tell it to do so.
  10. Special parameter '--' indicates that all parameters are complete. Any parameters after the command line are considered as operands, even if they start '-'
  11. It does not matter how the options are arranged. However, for mutually exclusive options, when an option overwrites the settings of other options, it can be said that the last option takes effect. If the option with parameters already exists, the program should process these option parameters in order. For example, 'myprog-u Arnold-u jarn' and 'myprog-U "Arnold, Jane" 'are the same (you must process these parameters yourself, getopt () cannot handle this situation ).
  12. The sequence of allowed operands affects program behavior. However, these programs should be described in documents.
  13. The program that reads and writes a specified file should treat a single parameter '-' as a meaningful standard input or standard output (or as a parameter suitable for the program ).

GNU Long Options

GNU encourages programmers to use long options in the form of -- help and -- verbose. These options do not conflict with POSIX conventions, but are easy to remember. They also provide the opportunity to maintain consistency among all GNU tools. The GNU long option has its own conventions:

For GNU programs that have followed the POSIX conventions, each short option has a corresponding long option.

Additional Long Options for GNU do not need the corresponding short options. We recommend that you have them.

The length option can be abbreviated as a string with the minimum uniqueness.

The option parameter and the long option are separated by a blank character or a '=.

The option parameter is optional (only valid for the short option ).

The length option can be prefixed with a dash.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.