/usr/bin/getopt: Difference between revisions
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
getopt - コマンドオプションを解析する(機能強化) | |||
SYNOPSIS | __TOC__ | ||
==SYNOPSIS == | |||
getopt optstring parameters | getopt optstring parameters | ||
getopt [options] [--] optstring parameters | getopt [options] [--] optstring parameters | ||
getopt [options] -o|--options optstring [options] [--] parameters | getopt [options] -o|--options optstring [options] [--] parameters | ||
DESCRIPTION | ==DESCRIPTION== | ||
getopt is used to break up (parse) options in command lines for easy parsing by shell procedures, | getopt is used to break up (parse) options in command lines for easy parsing by shell procedures, | ||
and to check for valid options. It uses the GNU getopt(3) routines to do this. | and to check for valid options. It uses the GNU getopt(3) routines to do this. | ||
Line 30: | Line 32: | ||
tion (-T) can be used. | tion (-T) can be used. | ||
OPTIONS | == OPTIONS == | ||
-a, --alternative | -a, --alternative | ||
Allow long options to start with a single '-'. | Allow long options to start with a single '-'. | ||
Line 79: | Line 81: | ||
Display version information and exit. No other output is generated. | Display version information and exit. No other output is generated. | ||
PARSING | == PARSING == | ||
This section specifies the format of the second part of the parameters of getopt (the parameters in | This section specifies the format of the second part of the parameters of getopt (the parameters in | ||
the SYNOPSIS). The next section (OUTPUT) describes the output that is generated. These parameters | the SYNOPSIS). The next section (OUTPUT) describes the output that is generated. These parameters | ||
Line 111: | Line 113: | ||
first non-option parameter is found. | first non-option parameter is found. | ||
OUTPUT | == OUTPUT == | ||
Output is generated for each element described in the previous section. Output is done in the same | Output is generated for each element described in the previous section. Output is done in the same | ||
order as the elements are specified in the input, except for non-option parameters. Output can be | order as the elements are specified in the input, except for non-option parameters. Output can be | ||
Line 145: | Line 147: | ||
preceding occurrences of '-' and '+' are ignored). | preceding occurrences of '-' and '+' are ignored). | ||
QUOTING | ==QUOTING== | ||
In compatible mode, whitespace or 'special' characters in arguments or non-option parameters are not | In compatible mode, whitespace or 'special' characters in arguments or non-option parameters are not | ||
handled correctly. As the output is fed to the shell script, the script does not know how it is | handled correctly. As the output is fed to the shell script, the script does not know how it is | ||
Line 162: | Line 164: | ||
used. | used. | ||
SCANNING MODES | ==SCANNING MODES== | ||
The first character of the short options string may be a '-' or a '+' to indicate a special scanning | The first character of the short options string may be a '-' or a '+' to indicate a special scanning | ||
mode. If the first calling form in the SYNOPSIS is used they are ignored; the environment variable | mode. If the first calling form in the SYNOPSIS is used they are ignored; the environment variable | ||
Line 177: | Line 179: | ||
parameter in this mode. | parameter in this mode. | ||
COMPATIBILITY | ==COMPATIBILITY== | ||
This version of getopt(1) is written to be as compatible as possible to other versions. Usually you | This version of getopt(1) is written to be as compatible as possible to other versions. Usually you | ||
can just replace them with this version without any modifications, and with some advantages. | can just replace them with this version without any modifications, and with some advantages. | ||
Line 192: | Line 194: | ||
In compatibility mode, leading '-' and '+' characters in the short options string are ignored. | In compatibility mode, leading '-' and '+' characters in the short options string are ignored. | ||
RETURN CODES | ==RETURN CODES== | ||
getopt returns error code 0 for successful parsing, 1 if getopt(3) returns errors, 2 if it does not | getopt returns error code 0 for successful parsing, 1 if getopt(3) returns errors, 2 if it does not | ||
understand its own parameters, 3 if an internal error occurs like out-of-memory, and 4 if it is | understand its own parameters, 3 if an internal error occurs like out-of-memory, and 4 if it is | ||
called with -T. | called with -T. | ||
EXAMPLES | ==EXAMPLES== | ||
Example scripts for (ba)sh and (t)csh are provided with the getopt(1) distribution, and are in‐ | Example scripts for (ba)sh and (t)csh are provided with the getopt(1) distribution, and are in‐ | ||
stalled in /usr/share/doc/util-linux/getopt/ directory. | stalled in /usr/share/doc/util-linux/getopt/ directory. | ||
ENVIRONMENT | ==ENVIRONMENT== | ||
POSIXLY_CORRECT | POSIXLY_CORRECT | ||
This environment variable is examined by the getopt(3) routines. If it is set, parsing stops | This environment variable is examined by the getopt(3) routines. If it is set, parsing stops | ||
Line 211: | Line 213: | ||
Forces getopt to use the first calling format as specified in the SYNOPSIS. | Forces getopt to use the first calling format as specified in the SYNOPSIS. | ||
BUGS | ==BUGS== | ||
getopt(3) can parse long options with optional arguments that are given an empty optional argument | getopt(3) can parse long options with optional arguments that are given an empty optional argument | ||
(but cannot do this for short options). This getopt(1) treats optional arguments that are empty as | (but cannot do this for short options). This getopt(1) treats optional arguments that are empty as | ||
Line 219: | Line 221: | ||
set them explicitly to the empty string). | set them explicitly to the empty string). | ||
AUTHOR | ==AUTHOR== | ||
Frodo Looijaard ⟨frodo@frodo.looijaard.name⟩ | Frodo Looijaard ⟨frodo@frodo.looijaard.name⟩ | ||
SEE ALSO | ==SEE ALSO== | ||
bash(1), tcsh(1), getopt(3) | bash(1), tcsh(1), getopt(3) | ||
AVAILABILITY | ==AVAILABILITY== | ||
The getopt command is part of the util-linux package and is available from Linux Kernel Archive | The getopt command is part of the util-linux package and is available from Linux Kernel Archive | ||
⟨https://www.kernel.org/pub/linux/utils/util-linux/⟩. | ⟨https://www.kernel.org/pub/linux/utils/util-linux/⟩. |