Getopt manual page






















The getopt function incrementally parses a command line argument list argv and returns the next known option character. An option character is known if it has been specified in the string of accepted option characters, optstring. The option string optstring may contain the following elements: individual characters, and characters followed by a colon to indicate an option . getopt (1) manual page NAME. SYNOPSIS. DESCRIPTION. It uses the GNU getopt (3) routines to do this. The parameters getopt is called with can be divided into OPTIONS. Allow long options to start with a single ’ − ’. Output a small usage guide and exit successfully. PARSING. This section. DESCRIPTION top. The getopt () function parses the command-line arguments. Its arguments argc and argv are the argument count and array as passed to the main () function on program invocation. An element of argv that starts with '-' (and is not exactly "-" or "--") is an option element. The characters of this element (aside from the initial.


getopt (PHP 4 = , PHP 5, PHP 7, PHP 8) getopt — Gets options from the command line argument list. DESCRIPTION top. The getopt () function parses the command-line arguments. Its arguments argc and argv are the argument count and array as passed to the main () function on program invocation. An element of argv that starts with '-' (and is not exactly "-" or "--") is an option element. The characters of this element (aside from the initial. getopt_long() can be used in two ways. In the first way, every long option understood by the program has a corresponding short option, and the option structure is only used to translate from long options to short options. When used in this fashion, getopt_long() behaves identically to getopt(3). This is a good way to add long option processing.


It has to do with how the shell handles the command line, more than PHP. PHP's getopt() is modeled on and probably built upon the Unix/POSIX/C library getopt(3) which treats strings as strings, and does not break them apart on white space. Here's proof: $ cat www.doorway.ru #! /usr/local/bin/php getopt ("f:"); print_r ($options);?. Example of Parsing Arguments with getopt. Here is an example showing how getopt is typically used. The key points to notice are: Normally, getopt is called in a loop. When getopt returns -1, indicating no more options are present, the loop terminates. A switch statement is used to dispatch on the return value from getopt. In typical use. The getopt function returns -1 when the argument list is exhausted. The interpretation of options in the argument list may be cancelled by the option ‘--’ (double dash) which causes getopt to signal the end of argument processing and return When all options have been processed (i.e., up to the first non-option argument), getopt returns

0コメント

  • 1000 / 1000