Browsing Chinese (Simplified) translation

525 of 581 results
525.
Parse option arguments.

Getopts is used by shell procedures to parse positional parameters
as options.

OPTSTRING contains the option letters to be recognized; if a letter
is followed by a colon, the option is expected to have an argument,
which should be separated from it by white space.

Each time it is invoked, getopts will place the next option in the
shell variable $name, initializing name if it does not exist, and
the index of the next argument to be processed into the shell
variable OPTIND. OPTIND is initialized to 1 each time the shell or
a shell script is invoked. When an option requires an argument,
getopts places that argument into the shell variable OPTARG.

getopts reports errors in one of two ways. If the first character
of OPTSTRING is a colon, getopts uses silent error reporting. In
this mode, no error messages are printed. If an invalid option is
seen, getopts places the option character found into OPTARG. If a
required argument is not found, getopts places a ':' into NAME and
sets OPTARG to the option character found. If getopts is not in
silent mode, and an invalid option is seen, getopts places '?' into
NAME and unsets OPTARG. If a required argument is not found, a '?'
is placed in NAME, OPTARG is unset, and a diagnostic message is
printed.

If the shell variable OPTERR has the value 0, getopts disables the
printing of error messages, even if the first character of
OPTSTRING is not a colon. OPTERR has the value 1 by default.

Getopts normally parses the positional parameters ($0 - $9), but if
more arguments are given, they are parsed instead.

Exit Status:
Returns success if an option is found; fails if the end of options is
encountered or an error occurs.
There are line breaks here. Each one represents a line break. Start a new line in the equivalent position in the translation.
There are leading/trailing spaces here. Each one represents a space character. Enter a space in the equivalent position in the translation.
解析选项参数。

getopts 被 shell 过程用于解析可定位的参数作为选项。


OPTSTRING 字符串包含待识别的选项字母;如果一个字母后面跟
着分号,则该选项需要一个参数,而该参数应用空格与选项分开。


每次启动时,getopts 会将下一个选项放到 shell 变量 $name
中,如果 name 变量不存在则先将其初始化,而下一个待处
理的参数序号放入 shell 变量 OPTIND 中。OPTIND 变量在每
次 shell 或者 shell 脚本启动时都被初始化为1。当一个选项要
求有一个参数时,getopts 将参数放入 shell 变量 OPTARG
中。

getopts 有两种报告错误的方法。如果 OPTSTRING 变量的第
一个字符是冒号,getopts 使用沉默错误报告。在这种模式
下,不会打印错误消息。如果看到了一个无效的选项,
getopts 将找到的选项字符放至 OPTARG 变量中。如果一个必
须的选项没有找到,getopts 放一个 ':' 到 NAME 变量中并且设
置 OPTARG 变量为找到的选项字符。如果 getopts 不在沉默模
式中,并且遇到了一个无效的选项,getopts 放置一个 '?' 到 NAME
变量中并且取消设定 OPTARG变量。如果必须的选项没有找到,
一个'?'会被放入 NAME变量中,OPTARG 将被取消设定,并且会
打印一个诊断信息。

如果 shell 变量 OPTERR 的值为0,getopts 禁用
错误信息的打印,即使 OPTSTRING 变量的第一个字符不是一
个冒号。OPTERR 的默认值为1.

getopts 通常解析可定位的参数($0 - $9),不过如果提供了
更多的参数,它们反而会被解析。

退出状态:
如果一个选项被找到则返回成功;如果遇到了选项的结尾或者
有错误发生则返回失败。
Translated by Boyuan Yang
Located in builtins.c:646
525 of 581 results

This translation is managed by Ubuntu Simplified Chinese Translators, assigned by Ubuntu Translators.

You are not logged in. Please log in to work on translations.