|
|
1.1 root 1: .if t .ds ' \[email protected]@\s+4\[email protected]@\'\[email protected]@\s-4\[email protected]@ 2: .if n .ds ' ' 3: .if t .ds ` \[email protected]@\s+4\[email protected]@\`\[email protected]@\s-4\[email protected]@ 4: .if n .ds ` ` 5: .TH GETOPT 1 6: .SH NAME 7: getopt \- parse command options 8: .SH SYNOPSIS 9: .B set \-\- \*`getopt optstring $\(**\*` 10: .SH DESCRIPTION 11: .I Getopt\^ 12: is used to break up options in command lines for easy parsing by shell 13: procedures, and to check for legal options. 14: .I Optstring\^ 15: is a string of recognized option letters (see getopt(3C)); 16: if a letter is followed by a colon, the option 17: is expected to have an argument which may or 18: may not be separated from it by white space. 19: The special option \fB\-\-\fP is used to delimit the end of the 20: options. 21: .I Getopt\^ 22: will place \fB\-\-\fP in the arguments at the end 23: of the options, or recognize it if used explicitly. 24: The shell arguments ($1 $2 . . .) are reset so that each option 25: is preceded by a \fB\-\fP and in its own shell argument; each option 26: argument is also in its own shell argument. 27: .SH DIAGNOSTICS 28: .I Getopt\^ 29: prints an error message on 30: the standard error 31: when it encounters an option letter not included in 32: .IR optstring . 33: .SH EXAMPLES 34: The following code fragment shows how one might process the arguments 35: for a command that can take the options 36: .B a 37: and 38: .BR b , 39: and the option 40: .BR o , 41: which requires an argument. 42: .PP 43: .RS 44: .nf 45: .ss 18 46: set \-\- \*`getopt abo: $\(**\*` 47: if [ $? != 0 ] 48: then 49: echo $USAGE 50: exit 2 51: fi 52: for i in $\(** 53: do 54: case $i in 55: \-a \(bv \-b) FLAG=$i; shift;; 56: \-o) OARG=$2; shift; shift;; 57: \-\-) shift; break;; 58: esac 59: done 60: .fi 61: .ss 12 62: .RE 63: .PP 64: This code will accept any of the following as equivalent: 65: .PP 66: .RS 67: .nf 68: .ss 18 69: cmd \-aoarg file file 70: cmd \-a \-o arg file file 71: cmd \-oarg \-a file file 72: cmd \-a \-oarg \-\- file file 73: .fi 74: .ss 12 75: .RE 76: .SH SEE ALSO 77: .IR sh (1), 78: .IR getopt (3C).
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.