Fetching latest commit…
Cannot retrieve the latest commit at this time
|Failed to load latest commit information.|
BASH OPTPARSE an advanced command line parsing system for Bash ======================== Copyright (C) 2011 Carlo Baldassi <firstname.lastname@example.org> This program brings into bash a method for parsing the command line which is somehow similar in spirit to python's optparse, or boost::program_options or others, i.e. it provides a framework in which the program options and arguments are described in a compact format and passed to bash_optparse, which in turn produces a portion of bash script which performs the parsing, sets default values, implements dynamic checks for type and range of the variables, auto-generates a nicely formatted usage() function etc. The typical usage in a script could be something like this: . bash_optparse << EOF OPTIONS_BEGIN perc FLOAT x [0:100] 50 "Select percentage" OPTIONS_END ARGUMENTS_BEGIN infile False "input file" ARGUMENTS_END EOF The OPTION line in the example describes a long option named --perc, associated to a varaible of the same name, of type FLOAT, whose range is between 0 and 100, and which defaults to 50. A short option -p is also automatically added as an alias to the long option. The corresponding help line in the auto-generated usage output would be: -p, --perc <x> Select percentage (<x>=float in [0.0:100.0], default=50) The ARGUMENT line describes how to pass an optional argument, which will be stored in the variable $infile. See `example_script_simple', `example_functions' and `example_script' in the `doc' directory for more information. The explanation of the syntax can be found in the comments to the `example_script' code.