下载此文档

linux getopts 学习笔记(Linux getopts 学习笔记).doc


文档分类:IT计算机 | 页数:约16页 举报非法文档有奖
1/16
下载提示
  • 1.该资料是网友上传的,本站提供全文预览,预览什么样,下载就什么样。
  • 2.下载该文档所得收入归上传者、原创者。
  • 3.下载的文档,不会出现我们的网址水印。
1/16 下载此文档
文档列表 文档介绍
linux getopts 学****笔记(Linux getopts 学****笔记)
Options for getting UNIX types:
One of the advantages of UNIX is that the standard mand has the mand line format in execution:
Command -options parameters
If the Shell program is used, the Bourne Shell provides a statement to obtain and mand line options, that is, the getopts statement. The format of the statement is:
Getopts option_string variable
Among them, option_string contains an effective single character option. If the mand finds a hyphen in mand line, it pare the characters behind the hyphen with the option_string. If there is a match, the value of the variable variable is set to this option. If there is no matching, is variable set as?. When getopts finds that there is no character behind the hyphen, a nonzero state value is returned. In Shell programs, a loop can be established by using the return value of getopts.
Sometimes a value is added to the option, and the mand also supports this functionality. Then you need to add a colon to the letter in the option_string. When the mand finds the colon, the value is read from mand line. If this value exists, it will be present in a special variable OPTARG. If this value does not exist, the mand stores a question mark in the OPTARG and displays a message on the
standard error output.
The optstring option string matches one by one
Varname options for essful matching each time
The Arg parameter list, when not written, takes mand line parameter list
$OPTIND special variable, option index, will increase by degrees, with an initial value of 1
$OPTARG special variable, option argument, has different values in different situations
Rule 1: when optstring with ":" at the beginning, getopts will distinguish between invalid option errors and miss option argument errors.
When invalid option, Varname will be set? $OPTARG is the option of the problem;
When Miss option argument, Varname is set as: $OPTARG is the option of the problem.
If optstring does not, "start", "inva

linux getopts 学习笔记(Linux getopts 学习笔记) 来自淘豆网www.taodocs.com转载请标明出处.

非法内容举报中心
文档信息
  • 页数16
  • 收藏数0 收藏
  • 顶次数0
  • 上传人rjmy2261
  • 文件大小24 KB
  • 时间2017-11-22