getopt.1
来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· 1 代码 · 共 81 行
1
81 行
.TH getopt 1.SH Namegetopt \- parse command options.SH Syntax.NXR "getopt command".B set \- \- \*\`getopt optstring.B $\(**\*\`.SH Description.NXR "getopt command"The.PN getoptcommandbreaks up options in command lines for easy parsing by Shellprocedures and checks for legal options.The.B optstringoption letters are recognizedif a letter is followed by a colon, the optionexpects an argument which may ormay not be separated from it by white space.For further information, see .MS getopt 3 ..PPThe special option, specified by two minus signs (\- \-), delimits the end of theoptions. If the delimiters are used explicitly, .PN getoptrecognizes it;otherwise,.PN getoptgenerates it.In either case,.PN getoptplaces the delimiter at the end of the options.The positional parameters ($1 $2 ...) of the shell are resetso that each optionis preceded by a single minus sign (\-) and is in its own positional parameter; each option argument is also parsed into its own positional parameter..SH ExamplesThe following code fragment shows how you can process the argumentsfor a command that can take the options.B aor.B b,as well as the option.B o,which requires an argument:.EX#!/bin/sh5set \-\- \*\`getopt abo: $\(**\*\`if [ $? != 0 ]then echo $\s-1USAGE\s+1 exit 2fifor i in $\(**do case $i in \-a \(bv \-b) \s-1FLAG\s+1=$i; shift;; \-o) \s-1OARG\s+1=$2; shift 2;; \-\-) shift; break;; esacdone.EEThis code accepts any of the following as equivalent:.EXcmd \-aoarg file filecmd \-a \-o arg file filecmd \-oarg \-a file filecmd \-a \-oarg \-\- file file.EE.SH DiagnosticsThe.PN getoptcommand prints an error message on the standard errorwhen it encounters an option letter not included in.IR optstring ..SH See Alsosh5(1), getopt(3)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?