[JM:01556] [POST:DP] util-linux getopt.1

アーカイブの一覧に戻る
Yuichi SATO ysato****@ybb*****
2019年 7月 26日 (金) 21:09:44 JST


<STATUS>
stat: DP
ppkg: util-linux
page: getopt.1
date: 2019/07/26
mail: ysato****@ybb*****
name: SATO Yuichi
</STATUS>

.\"
.\" Japanese Version Copyright (c) 2001-2019 Yuichi SATO
.\"         all rights reserved.
.\" Translated Tue 11 Jan 1994
.\"         by NetBSD jman proj. <jman****@spa*****>
.\" Updated Sun Jan 14 04:46:37 JST 2001
.\"         by Yuichi SATO <sato****@compl*****>
.\" Updated & Modified Sun Mar  2 15:11:49 JST 2003
.\"         by Yuichi SATO <ysato****@yahoo*****>
.\" Updated & Modified Wed Jul 24 13:55:29 JST 2019
.\"         by Yuichi SATO <ysato****@ybb*****>
.\"
.\"WORD:	parse		解析する
.\"WORD:	interpret	解釈する
.\"
.TH GETOPT "1" "December 2014" "util-linux" "User Commands"
.\"O .SH NAME
.SH 名前
.\"O getopt \- parse command options (enhanced)
getopt \- コマンドの引き数を解析する (拡張版)
.\"O .SH SYNOPSIS
.SH 書式
.B getopt
.I optstring parameters
.br
.B getopt
[options]
.RB [ \-\- ]
.I optstring parameters
.br
.B getopt
[options]
.BR \-o | \-\-options
.I optstring
[options]
.RB [ \-\- ]
.I parameters
.\"O .SH DESCRIPTION
.SH 説明
.\"O .B getopt
.\"O is used to break up
.\"O .RI ( parse )
.\"O options in command lines for easy parsing by shell procedures, and to
.\"O check for valid options.  It uses the
.\"O .SM GNU
.\"O .BR getopt (3)
.\"O routines to do this.
.B getopt
は、シェル手続きで簡単に解析できるように、
コマンドラインのオプションを分解
.RI ( 解析 )
するために使われる。
また、正しいオプションであるかを調べるためにも使われる。
これを行うために
.SM GNU
.BR getopt (3)
ルーチンが使われる。
.PP
.\"O The parameters
.\"O .B getopt
.\"O is called with can be divided into two parts: options which modify
.\"O the way
.\"O .B getopt
.\"O will do the parsing
.\"O .RI "(the " options
.\"O and the
.\"O .I optstring
.\"O in the
.\"O .BR SYNOPSIS ),
.\"O and the parameters which are to be parsed
.\"O .RI ( parameters
.\"O in the
.\"O .BR SYNOPSIS ).
.B getopt
を呼び出すときに使われたパラメータは、
2 つの部分に分けることができる:
.B getopt
の解析動作を変更するオプション
.RB ( 「書式」
セクションの
.I options
と
.IR optstring )
と、解析されるパラメータ
.RB ( 「書式」
セクションの
.IR parameters )
である。
.\"O The second part will start at the first non\-option parameter that is
.\"O not an option argument, or after the first occurrence of
.\"O .RB ' \-\- '.
.\"O If no
.\"O .RB ' \-o '
.\"O or
.\"O .RB ' \-\-options '
.\"O option is found in the first part, the first parameter of the second
.\"O part is used as the short options string.
第 2 部分は、
最初のオプションではないパラメータ
(オプション引き数ではないもの) の後か、
最初の
.B ' \-\- '
の後から始まる。
第 1 部分に
.RB ' \-o '
または
.RB ' \-\-options '
オプションが見つからない場合、
第 2 部分の最初のパラメータは
短い形式のオプション文字列として使われる。
.PP
.\"O If the environment variable
.\"O .B GETOPT_COMPATIBLE
.\"O is set, or if the first
.\"O .I parameter
.\"O is not an option (does not start with a
.\"O .RB ' \- ',
.\"O the first format in the
.\"O .BR SYNOPSIS ),
.\"O .B getopt
.\"O will generate output that is compatible with that of other versions of
.\"O .BR getopt (1).
環境変数
.B GETOPT_COMPATIBLE
が設定された場合、
または最初のパラメータがオプションでなかった場合
.RB (' \- '
で始まっていない場合。
これは
.B 「書式」
セクションの最初の形式である)、
.B getopt
は他のバージョンの
.BR getopt (1)
と互換性のある出力を生成する。
.\"O It will still do parameter shuffling and recognize optional arguments
.\"O (see section
.\"O .B COMPATIBILITY
.\"O for more information).
この場合でも、パラメータの並べ替えを行い、オプション引き数を認識する
(詳細は
.B 「互換性」
セクションを参照すること)。
.PP
.\"O Traditional implementations of
.\"O .BR getopt (1)
.\"O are unable to cope with whitespace and other (shell-specific)
.\"O special characters in arguments and non\-option parameters.  To solve
.\"O this problem, this implementation can generate quoted output which
.\"O must once again be interpreted by the shell (usually by using the
.\"O .B eval
.\"O command).  This has the effect of preserving those characters, but
.\"O you must call
.\"O .B getopt
.\"O in a way that is no longer compatible with other versions (the second
.\"O or third format in the
.\"O .BR SYNOPSIS ).
伝統的な
.BR getopt (1)
の実装では、引き数やオプションではないパラメータで
空白と他の (シェル特有の) 特殊文字を組み合わせて使うことができない。
この問題を解決するため、
この実装ではクォートした出力を生成する。
この出力は、シェル (通常は
.B eval
コマンドが使われる) によって再び解析されなければならない。
これにはクォートすべき文字列を保護するという効果があるが、
.B getopt
を他のバージョンとは互換性のない方法
.RB ( 「書式」
セクションの 2, 3 番目の形式) で呼び出さなければならない。
.\"O To determine whether this enhanced version of
.\"O .BR getopt (1)
.\"O is installed, a special test option
.\"O .RB ( \-T )
.\"O can be used.
拡張版の
.BR getopt (1)
がインストールされているかどうかを調べるには、特別なテストオプション
.RB ( \-T )
を使うことができる。
.\"O .SH OPTIONS
.SH オプション
.TP
.BR \-a , " \-\-alternative"
.\"O Allow long options to start with a single
.\"O .RB ' \- '.
長いオプションを 1 個の
.RB ' \- '
で始めることができるようにする。
.TP
.BR \-h , " \-\-help"
.\"O Display help text and exit.  No other output is generated.
ヘルプを表示して、終了する。
それ以上は何も出力されない。
.TP
.BR \-l , " \-\-longoptions \fIlongopts\fP"
.\"O The long (multi\-character) options to be recognized.  More than one
.\"O option name may be specified at once, by separating the names with
.\"O commas.  This option may be given more than once, the
.\"O .I longopts
.\"O are cumulative.  Each long option name in
.\"O .I longopts
.\"O may be followed by one colon to indicate it has a required argument,
.\"O and by two colons to indicate it has an optional argument.
認識させる長い (複数文字の) オプションを指定する。
2 つ以上のオプション名をコンマで区切って一度に指定できる。
このオプションは 2 回以上指定することができる。
.I longopts
は交換可能である。
.I longopts
で指定されている長いオプション名の後に、1 個のコロンを続けることができる。
これは、そのオプションに引き数が必須であることを示す。
また、長いオプション名の後に 2 個のコロンを続けることもできる。
これは、そのオプションが引き数を取る場合もあることを示す。
.TP
.BR \-n , " \-\-name \fIprogname\fP"
.\"O The name that will be used by the
.\"O .BR getopt (3)
.\"O routines when it reports errors.  Note that errors of
.\"O .BR getopt (1)
.\"O are still reported as coming from getopt.
エラーが報告された場合に
.BR getopt (3)
ルーチンが使うプログラム名。
このオプションを指定しても、
.BR getopt (1)
のエラーは getopt から発生したものとして表示される点に注意すること。
.TP
.BR \-o , " \-\-options \fIshortopts\fP"
.\"O The short (one\-character) options to be recognized.  If this option
.\"O is not found, the first parameter of
.\"O .B getopt
.\"O that does not start with a
.\"O .RB ' \- '
.\"O (and is not an option argument) is used as the short options string.
認識させる短い (1 文字の) オプションを指定する。
このオプションが指定されていない場合、
.B getopt
の 1 個の
.RB ' \- '
で始まっていない最初のパラメータ (かつ、オプションの引き数でないもの) が
短いオプションの文字列として使われる。
.\"O Each short option character in
.\"O .I shortopts
.\"O may be followed by one colon to indicate it has a required argument,
.\"O and by two colons to indicate it has an optional argument.  The first
.\"O character of shortopts may be
.\"O .RB ' + '
.\"O or
.\"O .RB ' \- '
.\"O to influence the way options are parsed and output is generated (see
.\"O section
.\"O .B SCANNING MODES
.\"O for details).
.I shortopts
に指定されている短いオプション文字の後に、1 個のコロンを続けることができる。
これは、そのオプションに引き数が必須であることを示す。
また、長いオプション名の後に 2 個のコロンを続けることもできる。
これは、そのオプションが引き数を取る場合もあることを示す。
オプションの解析法と出力の生成法を変更するために、
shortopts の最初の文字を
.RB ' + '
または
.RB ' \- '
にすることができる
(詳細は
.B 「スキャンモード」
セクションを参照すること)。
.TP
.BR \-q , " \-\-quiet"
.\"O Disable error reporting by getopt(3).
getopt(3) によるエラー表示をさせない。
.TP
.BR  \-Q , " \-\-quiet\-output"
.\"O Do not generate normal output.  Errors are still reported by
.\"O .BR getopt (3),
.\"O unless you also use
.\"O .BR \-q .
通常の出力を生成させない。
.IR \-q
を指定しない限り、
.BR getopt (3)
によってエラーが表示される。
.TP
.BR \-s , " \-\-shell \fIshell\fP"
.\"O Set quoting conventions to those of
.\"O .IR shell .
.\"O If the \fB\-s\fR option is not given, the
.\"O .SM BASH
.\"O conventions are used.  Valid arguments are currently
.\"O .RB ' sh '
.\"O .RB ' bash ',
.\"O .RB ' csh ',
.\"O and
.\"O .RB ' tcsh '.
指定したシェルのクォート方法に設定する。
\-s オプションが指定されていない場合、
.SM BASH
でのクォート方法が使われる。
指定可能な引き数は、現在のところ
.RB ' sh ',
.RB ' bash ',
.RB ' csh ',
.RB ' tcsh '
である。
.TP
.BR \-T , " \-\-test"
.\"O Test if your
.\"O .BR getopt (1)
.\"O is this enhanced version or an old version.  This generates no
.\"O output, and sets the error status to 4.  Other implementations of
.\"O .BR getopt (1),
.\"O and this version if the environment variable
.\"O .B GETOPT_COMPATIBLE
.\"O is set, will return
.\"O .RB ' \-\- '
.\"O and error status 0.
.BR getopt (1)
が拡張バージョンか古いバージョンかをテストする。
何も出力しないが、エラーステータスを 4 に設定する。
他の
.BR getopt (1)
の実装の場合や、このバージョンで環境変数
.B GETOPT_COMPATIBLE
が設定されている場合、
.RB ' \-\- '
を返し、エラーステータスを 0 に設定する。
.TP
.BR \-u , " \-\-unquoted"
.\"O Do not quote the output.  Note that whitespace and special
.\"O (shell-dependent) characters can cause havoc in this mode (like they
.\"O do with other
.\"O .BR getopt (1)
.\"O implementations).
出力をクォートしない。
空白と (シェル依存の) 特殊文字は、(他の
.BR getopt (1)
の実装と同じように) このモードでは大混乱を引き起こす。
.TP
.BR \-V , " \-\-version"
.\"O Display version information and exit.  No other output is generated.
バージョン情報を表示して、終了する。
それ以上は何も出力されない。
.\"O .SH PARSING
.SH 解析
.\"O This section specifies the format of the second part of the
.\"O parameters of
.\"O .B getopt
.\"O (the
.\"O .I parameters
.\"O in the
.\"O .BR SYNOPSIS ).
このセクションでは
.B getopt
のパラメータの第 2 部分
.RB ( 「書式」
セクションの
.IR parameters )
のフォーマットについて説明している。
.\"O The next section
.\"O .RB ( OUTPUT )
.\"O describes the output that is generated.  These parameters were
.\"O typically the parameters a shell function was called with.  Care must
.\"O be taken that each parameter the shell function was called with
.\"O corresponds to exactly one parameter in the parameter list of
.\"O .B getopt
.\"O (see the
.\"O .BR EXAMPLES ).
次のセクション
.RB ( 出力 )
では生成される出力について説明している。
これらのパラメータは、一般に、シェル関数が呼ばれたときのパラメータである。
シェル関数が呼ばれたときの各パラメータが
.B getopt
のパラメータリストにある 1 つのパラメータに
厳密に対応している点に注意しなければならない
.RB ( 「例」
セクションを参照すること)。
.\"O All parsing is done by the GNU
.\"O .BR getopt (3)
.\"O routines.
全ての解析が GNU
.BR getopt (3)
ルーチンで行われる。
.PP
.\"O The parameters are parsed from left to right.  Each parameter is
.\"O classified as a short option, a long option, an argument to an
.\"O option, or a non\-option parameter.
パラメータは左から右へ解析される。
各パラメータは、短いオプション・長いオプション・オプションへの引き数・
オプションではないパラメータに分類される。
.PP
.\"O A simple short option is a
.\"O .RB ' \- '
.\"O followed by a short option character.  If the option has a required
.\"O argument, it may be written directly after the option character or as
.\"O the next parameter (i.e., separated by whitespace on the command
.\"O line).  If the option has an optional argument, it must be written
.\"O directly after the option character if present.
簡単な短いオプションは、
.RB ' \- '
の後に短いオプション文字が続くものである。
オプションが引き数を必須としている場合、
引き数はオプション文字の直後に書くことができる。
(コマンドライン上で空白で区切られた) 次のパラメータとして書くこともできる。
オプションが引き数を取ることも取らないこともできる場合、
引き数が存在するならば、オプション文字の直後に書かなければならない。
.PP
.\"O It is possible to specify several short options after one
.\"O .RB ' \- ',
.\"O as long as all (except possibly the last) do not have required or
.\"O optional arguments.
(最後のオプションを除く) 全てのオプションが
必須の引き数もオプションとしての引き数も必要としない限り、
1 個の
.RB ' \- '
の後に複数の短いオプションを指定することができる。
.PP
.\"O A long option normally begins with
.\"O .RB ' \-\- '
.\"O followed by the long option name.  If the option has a required
.\"O argument, it may be written directly after the long option name,
.\"O separated by
.\"O .RB ' = ',
.\"O or as the next argument (i.e., separated by whitespace on the command
.\"O line).  If the option has an optional argument, it must be written
.\"O directly after the long option name, separated by
.\"O .RB ' = ',
.\"O if present (if you add the
.\"O .RB ' = '
.\"O but nothing behind it, it is interpreted as if no argument was
.\"O present; this is a slight bug, see the
.\"O .BR BUGS ).
長いオプションは、通常
.RB ' \-\- '
の後に長いオプション名が続く。
オプションが引き数を必須としている場合、
.RB ' = '
で区切って長いオプション名の直後に書くことができる。
また、(コマンドライン上で空白で区切って) 次の引き数として書くこともできる。
オプションが引き数を取ることも取らないこともできる場合、
引き数が存在するならば、
.RB ' = '
で区切って長いオプション名の直後に書かなければならない
.RB (' = '
をオプションの後に書いたにも関らず、その後に何も指定しなかった場合、
引き数が存在しないものとして解釈される。
これはちょっとしたバグである。
.B 「バグ」
セクションを参照すること)。
.\"O Long options may be abbreviated, as long as the abbreviation is not
.\"O ambiguous.
長いオプションは、省略形が曖昧でない (他のオプションと区別がつく) 限り、
短く省略することができる。
.PP
.\"O Each parameter not starting with a
.\"O .RB ' \- ',
.\"O and not a required argument of a previous option, is a non\-option
.\"O parameter.  Each parameter after a
.\"O .RB ' \-\- '
.\"O parameter is always interpreted as a non\-option parameter.  If the
.\"O environment variable
.\"O .B POSIXLY_CORRECT
.\"O is set, or if the short option string started with a
.\"O .RB ' + ',
.\"O all remaining parameters are interpreted as non\-option parameters as
.\"O soon as the first non\-option parameter is found.
.RB ' \- '
で始まらず、かつ前のオプションが必須としている引き数でもないパラメータは、
オプションではないパラメータである。
.RB ' \-\- '
パラメータの後にあるパラメータは、
オプションではないパラメータとして解釈される。
環境変数
.B POSIXLY_CORRECT
が設定されている場合、
または短いオプション文字列が
.RB ' + '
で始まっている場合、
最初のオプションではないパラメータが見つかった時点で、
残りの全てのパラメータはオプションではないパラメータとして解釈される。
.\"O .SH OUTPUT
.SH 出力
.\"O Output is generated for each element described in the previous
.\"O section.  Output is done in the same order as the elements are
.\"O specified in the input, except for non\-option parameters.  Output
.\"O can be done in
.\"O .I compatible
.\"O .RI ( unquoted )
.\"O mode, or in such way that whitespace and other special characters
.\"O within arguments and non\-option parameters are preserved (see
.\"O .BR QUOTING ).
出力は前のセクションで説明した各要素に対して生成される。
出力は要素が入力で指定された順番で生成される。
ただし、オプションではないパラメータは例外である。
出力は
.I 互換
.RI ( クォートされない )
モードで生成することができる。
また、引き数とオプションではないパラメータに含まれる空白と他の特殊文字を
保護するモードで出力することもできる
.RB ( 「クォート」
セクションを参照すること)。
.\"O When the output is processed in the shell script, it will seem to be
.\"O composed of distinct elements that can be processed one by one (by
.\"O using the shift command in most shell languages).  This is imperfect
.\"O in unquoted mode, as elements can be split at unexpected places if
.\"O they contain whitespace or special characters.
出力がシェルスクリプトで処理される場合、
その出力は別々の要素から構成されているようにみえる。
この要素は (大部分のシェル言語では shift コマンドを使って)
1 つ 1 つ処理できる。
この動作はクォートされないモードでは不完全である。
なぜなら、要素に空白や特殊文字があった場合、
要素が期待していない箇所で分割されてしまうからである。
.PP
.\"O If there are problems parsing the parameters, for example because a
.\"O required argument is not found or an option is not recognized, an
.\"O error will be reported on stderr, there will be no output for the
.\"O offending element, and a non\-zero error status is returned.
必須とされる引き数が見つからない、またはオプションが認識されない、
といった原因でパラメータ解析に問題がある場合、
標準エラーにエラーが表示される。
このとき、不正な要素に対しては何も出力されず、
0 でないエラーステータスが返される。
.PP
.\"O For a short option, a single
.\"O .RB ' \- '
.\"O and the option character are generated as one parameter.  If the
.\"O option has an argument, the next parameter will be the argument.  If
.\"O the option takes an optional argument, but none was found, the next
.\"O parameter will be generated but be empty in quoting mode, but no
.\"O second parameter will be generated in unquoted (compatible) mode.
.\"O Note that many other
.\"O .BR getopt (1)
.\"O implementations do not support optional arguments.
短いオプションに対して、出力として 1 個の
.RB ' - '
とオプション文字が生成される。
オプションが引き数を取る場合、次のパラメータが引き数になる。
オプションが引き数を取っても取らなくてもよい場合に、
引き数が指定されていないと、
クォートモードでは次のパラメータが生成されるが空のパラメータになる。
この場合、クォートしない (互換) モードでは
2 番目のパラメータは生成されない。
他の多くの
.BR getopt (1)
の実装では、取っても取らなくてもよい引き数は
サポートされていない点に注意すること。
.PP
.\"O If several short options were specified after a single
.\"O .RB ' \- ',
.\"O each will be present in the output as a separate parameter.
複数の短いオプションが 1 個の
.RB ' \- '
の後に指定されている場合、
各オプションは区切られたパラメータとして出力に表示される。
.PP
.\"O For a long option,
.\"O .RB ' \-\- '
.\"O and the full option name are generated as one parameter.  This is
.\"O done regardless whether the option was abbreviated or specified with
.\"O a single
.\"O .RB ' \- '
.\"O in the input.  Arguments are handled as with short options.
長いオプションに対して、
.RB ' \-\- '
と完全なオプション名が 1 つのパラメータとして生成される。
「入力でオプションが略書きされている。
または、オプションが 1 個の
.RB ' \- '
を使って指定されている。」ということに関らず、この動作をする。
引き数は短いオプションとして扱われる。
.PP
.\"O Normally, no non\-option parameters output is generated until all
.\"O options and their arguments have been generated.  Then
.\"O .RB ' \-\- '
.\"O is generated as a single parameter, and after it the non\-option
.\"O parameters in the order they were found, each as a separate
.\"O parameter.  Only if the first character of the short options string
.\"O was a
.\"O .RB ' \- ',
.\"O non\-option parameter output is generated at the place they are found
.\"O in the input (this is not supported if the first format of the
.\"O .B SYNOPSIS
.\"O is used; in that case all preceding occurrences of
.\"O .RB ' \- '
.\"O and
.\"O .RB ' + '
.\"O are ignored).
通常、全てのオプションとその引き数が出力に生成されるまで、
オプションではないパラメータは出力されない。
そして、1 個のパラメータとして
.RB ' \-\- '
が生成される。
その後にオプションではないパラメータは、
見つかった順番で別々のパラメータとして生成される。
短いオプション文字列の最初の文字が
.RB ' \- '
である場合にのみ、
オプションではないパラメータは入力で見つかった位置で出力される
(この動作は
.B 「書式」
セクションの最初の形式が使われた場合にはサポートされない。
この場合、
.RB ' \- '
と
.RB ' + '
が前に付く全てのパラメータが無視される)。
.\"O .SH QUOTING
.SH クォート
.\"O In compatible mode, whitespace or 'special' characters in arguments
.\"O or non\-option parameters are not handled correctly.  As the output
.\"O is fed to the shell script, the script does not know how it is
.\"O supposed to break the output into separate parameters.  To circumvent
.\"O this problem, this implementation offers quoting.  The idea is that
.\"O output is generated with quotes around each parameter.  When this
.\"O output is once again fed to the shell (usually by a shell
.\"O .B eval
.\"O command), it is split correctly into separate parameters.
互換モードでは、引き数やオプションではないパラメータにある
空白や「特殊」文字は正しく扱われない。
この出力はシェルスクリプトに与えられるので、
スクリプトは、出力をどのようにして個々のパラメータに
分割すべきなのかを知らない。
この問題を回避するため、この実装ではクォート機能を提供する。
これは、各パラメータをクォートして出力を生成する、という手法を取る。
この出力がもう一度シェル (通常はシェルの
.B eval
コマンド) に与えられた場合、
出力は個々のパラメータに正しく分割される。
.PP
.\"O Quoting is not enabled if the environment variable
.\"O .B GETOPT_COMPATIBLE
.\"O is set, if the first form of the
.\"O .B SYNOPSIS
.\"O is used, or if the option
.\"O .RB ' \-u '
.\"O is found.
環境変数
.B GETOPT_COMPATIBLE
が設定された場合・
.B 「書式」
セクションの最初の形式が使われた場合・
.RB ' \-u '
オプションが指定された場合、クォートは行われない。
.PP
.\"O Different shells use different quoting conventions.  You can use the
.\"O .RB ' \-s '
.\"O option to select the shell you are using.  The following shells are
.\"O currently supported:
.\"O .RB ' sh ',
.\"O .RB ' bash ',
.\"O .RB ' csh '
.\"O and
.\"O .RB ' tcsh '.
.\"O Actually, only two 'flavors' are distinguished: sh\-like quoting
.\"O conventions and csh\-like quoting conventions.  Chances are that if
.\"O you use another shell script language, one of these flavors can still
.\"O be used.
クォートの規則はシェルごとに異なる。
使用しているシェルを選択するために
.RB ' \-s '
オプションを使うことができる。
以下のシェルで正しく機能する:
.RB ' sh ',
.RB ' bash ',
.RB ' csh ' ,
.RB ' tcsh '.
実際には、2 つの「方式」に分類される:
sh 式のクォート規則と csh 式のクォート規則である。
他のシェルスクリプト言語を使っている場合でも、
これらの方式のどちらかが使える可能性がある。

.\"O .SH "SCANNING MODES"
.SH スキャンモード
.\"O The first character of the short options string may be a
.\"O .RB ' \- '
.\"O or a
.\"O .RB ' + '
.\"O to indicate a special scanning mode.  If the first calling form in
.\"O the
.\"O .B SYNOPSIS
.\"O is used they are ignored; the environment variable
.\"O .B POSIXLY_CORRECT
.\"O is still examined, though.
特殊なスキャンモードであることを示すために、
短いオプションの最初の文字を
.RB ' \- '
または
.RB ' + '
にすることができる。
.B 「書式」
セクションの最初の呼び出し形式が使われた場合、これは無視される。
しかし、環境変数
.B POSIXLY_CORRECT
が指定されているかどうかは調べられる。
.PP
.\"O If the first character is
.\"O .RB ' + ',
.\"O or if the environment variable
.\"O .B POSIXLY_CORRECT
.\"O is set, parsing stops as soon as the first non\-option parameter
.\"O (i.e., a parameter that does not start with a
.\"O .RB ' \- ')
.\"O is found that is not an option argument.  The remaining parameters
.\"O are all interpreted as non\-option parameters.
最初の文字が
.RB ' + '
の場合、または環境変数
.B POSIXLY_CORRECT
が設定されている場合、オプションではない最初のパラメータ
(つまり、
.RB ' \- '
で始まっていないパラメータ) が
オプション引き数でないと分かった時点で解析はストップする。
それ以降の全てのパラメータは、オプションではないパラメータとして解釈される。
.PP
.\"O If the first character is a
.\"O .RB ' \- ',
.\"O non\-option parameters are outputted at the place where they are
.\"O found; in normal operation, they are all collected at the end of
.\"O output after a
.\"O .RB ' \-\- '
.\"O parameter has been generated.  Note that this
.\"O .RB ' \-\- '
.\"O parameter is still generated, but it will always be the last
.\"O parameter in this mode.
最初の文字が
.RB ' \- '
の場合、オプションではない引き数は見つかった箇所で出力される。
通常の操作では、
.RB ' \-\- '
パラメータが生成された後で、最後にまとめて出力される。
この場合でも
.RB ' \-\- '
パラメータは生成されるが、
通常このモードでは最後のパラメータになる点に注意すること。
.\"O .SH COMPATIBILITY
.SH 互換性
.\"O This version of
.\"O .BR getopt (1)
.\"O is written to be as compatible as possible to other versions.
.\"O Usually you can just replace them with this version without any
.\"O modifications, and with some advantages.
このバージョンの
.BR getopt (1)
は、出来るだけ他のバージョンと互換性があるように書かれた。
通常は他のバージョンを修正することなく、
このバージョンに置き換えることができる。
更に、いくつかの利点がある。
.PP
.\"O If the first character of the first parameter of getopt is not a
.\"O .RB ' \- ',
.\"O .B getopt
.\"O goes into compatibility mode.  It will interpret its first
.\"O parameter as the string of short options, and all other arguments
.\"O will be parsed.  It will still do parameter shuffling (i.e., all
.\"O non\-option parameters are output at the end), unless the
.\"O environment variable
.\"O .B POSIXLY_CORRECT
.\"O is set.
getopt の最初のパラメータの最初の文字が
.RB ' \- '
でない場合、getopt は互換モードになる。
最初のパラメータは短いオプションの文字列として解釈され、
他の全ての引き数が解析される。
この場合でも、環境変数
.B POSIXLY_CORRECT
が設定されていない限り、パラメータの並べ替えを行う
(つまり、オプションではない全てのパラメータが最後に出力される)。
.PP
.\"O The environment variable
.\"O .B GETOPT_COMPATIBLE
.\"O forces
.\"O .B getopt
.\"O into compatibility mode.  Setting both this environment variable and
.\"O .B POSIXLY_CORRECT
.\"O offers 100% compatibility for 'difficult' programs.  Usually, though,
.\"O neither is needed.
環境変数
.B GETOPT_COMPATIBLE
は
.B getopt
を強制的に互換モードにする。
この環境変数と
.B POSIXLY_CORRECT
の両方を設定すると、「難しい」プログラムのために 100% の互換性を提供する。
しかし、通常はどちらも設定する必要がない。
.PP
.\"O In compatibility mode, leading
.\"O .RB ' \- '
.\"O and
.\"O .RB ' + '
.\"O characters in the short options string are ignored.
互換モードでは、短いオプション文字列の最初に付く
.RB ' \- '
と
.RB ' + '
は無視される。
.\"O .SH RETURN CODES
.SH 返り値
.\"O .B getopt
.\"O returns error code
.\"O .B 0
.\"O for successful parsing,
.\"O .B 1
.\"O if
.\"O .BR getopt (3)
.\"O returns errors,
.\"O .B 2
.\"O if it does not understand its own parameters,
.\"O .B 3
.\"O if an internal error occurs like out\-of\-memory, and
.\"O .B 4
.\"O if it is called with
.\"O .BR \-T .
解析に成功した場合、
.B getopt
はエラーコード
.B 0
を返す。
.BR getopt (3)
がエラーを返した場合は
.B 1
を返す。
パラメータが理解できなかった場合は
.B 2
を返す。
メモリが足りない (out\-of\-memory) といった内部エラーの場合は
.B 3
を返す。
.BR \-T
オプションを付けて呼び出された場合は
.B 4
を返す。
.\"O .SH EXAMPLES
.SH 例
.\"O Example scripts for (ba)sh and (t)csh are provided with the
.\"O .BR getopt (1)
.\"O distribution, and are optionally installed in
.\"O .I /usr/share/getopt/
.\"O or
.\"O .I /usr/share/doc/
.\"O in the util-linux subdirectory.
(ba)sh と (t)csh での使用例のスクリプトは、
.BR getopt (1)
ディストリビューションで提供されている。
これらはオプションとして
.I /usr/share/getopt/
または
.I /usr/share/doc/
にインストールされている。
.\"O .SH ENVIRONMENT
.SH 環境変数
.IP POSIXLY_CORRECT
.\"O This environment variable is examined by the
.\"O .BR getopt (3)
.\"O routines.  If it is set, parsing stops as soon as a parameter is
.\"O found that is not an option or an option argument.  All remaining
.\"O parameters are also interpreted as non\-option parameters, regardless
.\"O whether they start with a
.\"O .RB ' \- '.
この環境変数は
.BR getopt (3)
ルーチンで調べられる。
これが設定されている場合、パラメータがオプションまたは
オプション引き数でないと分かった時点で解析は停止する。
それ以降の全てのパラメータは、
.RB ' \- '
で始まっているかどうかに関係なく、
オプションではないパラメータとして解釈される。
.IP GETOPT_COMPATIBLE
.\"O Forces
.\"O .B getopt
.\"O to use the first calling format as specified in the
.\"O .BR SYNOPSIS .
.B getopt
に対して強制的に
.B 「書式」
セクションの最初の呼び出し形式を使わせる。
.\"O .SH BUGS
.SH バグ
.\"O .BR getopt (3)
.\"O can parse long options with optional arguments that are given an
.\"O empty optional argument (but cannot do this for short options).
.\"O This
.\"O .BR getopt (1)
.\"O treats optional arguments that are empty as if they were not present.
.BR getopt (3)
は、引き数を取っても取らなくてもよい長いオプションを解析できる
(ただし、短いオプションの場合は解析できない)。
この
.BR getopt (1)
は、オプション引き数が指定されていない場合、それが存在しないものとして扱う。
.PP
.\"O The syntax if you do not want any short option variables at all is
.\"O not very intuitive (you have to set them explicitly to the empty
.\"O string).
短いオプション変数を全く使いたくない場合、
書式は全く直感的でないものになる
(明示的に空の文字列に設定する必要がある)。
.\"O .SH AUTHOR
.SH 著者
.MT frodo****@frodo*****
Frodo Looijaard
.ME
.\"O .SH "SEE ALSO"
.SH 関連項目
.BR bash (1),
.BR tcsh (1),
.BR getopt (3)
.\"O .SH AVAILABILITY
.SH 入手方法
.\"O The getopt command is part of the util-linux package and is available from
.\"O .UR https://\:www.kernel.org\:/pub\:/linux\:/utils\:/util-linux/
.\"O Linux Kernel Archive
.\"O .UE .
getopt コマンドは、util-linux パッケージの一部であり、
.UR https://\:www.kernel.org\:/pub\:/linux\:/utils\:/util-linux/
Linux Kernel Archive
.UE
から入手できる。



linuxjm-discuss メーリングリストの案内
アーカイブの一覧に戻る