Name
getopt
Synopsis
array getopt(stringshort_options[, arraylong_options])
Parses the command-line arguments list used to invoke the
current script and returns an associative array of optional name/value
pairs. The short_options and
long_options parameters define the
command-line arguments to parse.
The short_options parameter is a
single string, with each character representing a single argument
passed into the script via a single hyphen. For example, the short
options string "ar" matches the
command-line arguments -a -r. Any
character followed by a single colon : requires a value to match, while any
character followed by two colons ::
optionally includes a value to match. For example, "a:r::x" would match the command-line
arguments -aTest -r
-x but not -a -r
-x.
The long_options parameter is an
array of strings, with each element representing a single argument
passed into the script via a double hyphen. For example, the element
"verbose" matches the command-line
argument --verbose. All parameters
specified in the long_options parameter
optionally match values in the command line separated from the option
name with an equals sign. For example, "verbose" will match both --verbose and --verbose=1.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access