arguments

NAME

arguments - contains function to parse arguments and assign option values to variables.

FUNCTIONS

Where:

LIMITATION: grouping of one-letter options is NOT supported. Argument -abc will be parsed as option -abc, not as -a -b -c.

NOTE: bash4 requires to use "${@:+$@}" to expand empty list of arguments in strict mode (-u).

By default, function supports -h|--help, --man and --debug options. Options --help and --man are calling arguments::help() function with 2 or 1 as argument. Override that function if you want to provide your own help.

Unlike many other parsers, this function stops option parsing at first non-option argument.

Use -- in commandline arguments to strictly separate options and arguments.

After option parsing, unparsed command line arguments are stored in ARGUMENTS array.

Example:

# Boolean variable ("yes" or "no")
FOO="no"
# String variable
BAR=""
# Indexed array
declare -a BAZ=( )
# Integer variable
declare -i TIMES=0

arguments::parse \
   "-f|--foo)FOO;Yes" \
   "-b|--bar)BAR;String,Required" \
   "-B|--baz)BAZ;Array" \
   "-i|--inc)TIMES;Incremental,((TIMES<3))" \
   -- \
   "${@:+$@}"

# Print name and value of variables
dbg FOO BAR BAZ TIMES ARGUMENTS