getopt(3tlib)


getopt -- parse UNIX command line options

Synopsis

global argv optind optarg opterr
set argc [llength argv]
getopt $argc $argv $optstring

Description

getopt returns the next option letter in argv that matches a letter in optstr. It supports all the rules of the command syntax standard.

optstring must contain the option letters the command using getopt recognizes; if a letter is followed by a colon, the option is expected to have an argument, or group of arguments, which must be separated from it by white space.

Arguments


argc
count of list elements in argv, e.g. [llength argv]

argv
Tcl global, the command line argument vector.

optstring
list of valid single-letter options.

Globals


argv
Tcl command line argument vector

optind
Tcl list index in argv of next argument to be processed.

optarg
Tcl list index in argv of option argument.

opterr
boolean controlling error message on stderr. Defaults to 1. Set to 0 to suppress.

Return values

The next valid option letter from argv. ``?'' for an invalid option or missing option argument. ``-1'' when all command line options have been parsed. optarg points to the option argument if the returned option letter takes such and argument and it is present in argv.

optind is left pointing to the next argument in argv.

References

getopt(3C).

Notices

See getopt(3C) for complete details about valid command line syntax.
25 April 2004
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004