DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

getopt(TCL_ADM)


getopt -- parse UNIX command line options

Syntax

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.

Notes

See getopt(S) for complete details about valid command line syntax.

See also

getopt(S).
16 September 2002
© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003