GETOPTS(3) | 3 (libbash getopts library manual) | GETOPTS(3) |
getopts
— libbash
library for command line parameters parsing
$retval getopt_long
⟨Instructions⟩ ⟨Parameters⟩
Here is a table for reference:
The getopt_long function parses the command line arguments. It uses Instructions as the rules for parsing the Parameters.
A string that specifies rules for parameters parsing. The instructions string is built of a group of independent instructions, separated by a white space. Each instruction must have the following structure:
-<SingleLetter>|--<MultiLetter>-><VariableName>[:]
This structure contains three parts:
-h
.--help
.The Variable name can represent one of two variables types:
(not followed by
‘:
’)on
’ (i.e. was specified on
command line) and will not be defined if
‘off
’.(followed by
‘:
’)=
’
). If input contains more then one instance of the considered command
line option, an array of the given parameters will be set as the value
of the variable.The Parameters are simply the parameters you wish to parse.
This function returns a string that contains a set of variables definitions. In order to define the variables, this string should be given as a parameter to eval function. This value is returned in the variable $retval.
Parse command line parameters looking for the flags
-h
| --help
and
-v
| --version
and for the
value -p
| --path
:
getopt_long '-h|--help->HELP -v|--version->VERSION -p|--path->PATH:' $* eval $retval
In this example, for the parameters --help --path=/usr/ the variables that will be created are:
HELP=1 PATH=/usr/
for the parameters --help --path=/usr --path=/bin the variables that will be created are:
HELP=1 PATH=(/usr /bin)
Values must not contain the string `__getopts__'. This string will be parsed as a single white-space.
A value should not start with an already defined multi-letter sign. If such a value exists, it will be treated as the equivalent singe-letter sign. This bug only accures when using a single-letter sign, or a multi-letter sign that are not followed by a `='.
For example: If we have a script named `foo', and we parse the parameters `-d|--dir:' and `-f|--file:', then
foo -d --file
foo --dir --file
foo --dir=--file
Hai Zaar
⟨haizaar@haizaar.com⟩
Gil Ran ⟨gil@ran4.net⟩
ldbash(1), getopt_long(1), getopts(1), getopt(1), libbash(1), getopt(3), getopt_long(3)
Linux |