getopt_long_only

  • Version 3.5 and earlier:getopt_long_only() function not available.
  • Version 4.0 and later: getopt_long_only() function available.

Description

Breaks up command lines for easy parsing and to check for legal options. This function examines a list of arguments for long-style options only.

A long option usually consists of two dashes followed by a name and possibly a parameter. When using the long-only version of getopt, the function also recognizes a single dash at the front of an option. For example, in the command command –-option1 –-option2=2 –-option3 parameter --option4, --option1 and --option4 are long options with no parameters, and --option2 and --option3 are options with extra parameters.

On the first invocation, it examines the first argument. On subsequent invocations, it picks up from where it left off and examines the next argument.

Syntax

result = getopt_long_only (argc, argv, short-option-string, long-option-list)

Arguments

argc Required. Number. The number of entries in the argument array list argv.
argv Required. List. The argument array to process.
short-option-string Required. Although this function does not process short options, the entry is still available to specify the leading control modifiers. The leading characters of the short option string may modify the search characteristics as follows: A leading + stops parsing as soon as the first non-option parameter is found that is not an option argument. All other parameters are treated as non-option strings. A leading returns non-option parameters at the place where they are found.
long-option-list Required. List. A list of strings that contains the long options. Each parameter can be followed by a single colon (:), to indicate it has a required parameter, or two colons (::) to indicate that it may have an optional parameter.

Return Values

If a valid option is found, then the function returns that option. If an optional or required argument is associated with the option, then the policy variable optarg contains the value of that argument.

If no valid option is found, or if a required argument is missing, then a question mark (?) is returned. The variable optchar is set to the letter of the problem option.

When the end of the argument list is found, an empty string, "", is returned.

The variable optind is set to the subscript of the next string in the argv list.

result = getopt_long_only (...)

For more information, see the following: