bash-argparse is a tool to parse your bash scripts command-line arguments.
- Specify command-line arguments from a signature
- Short and long options
- Positional and optional arguments
- Type checking
- Default values
- Only requires a standard python (>= 3.7) installation
- Ease-of-use: If you already know any typed programming language,
bash-argparsemay feel more intuitive, since the script signature resembles a normal function definition. - Type Safety: Skip writing input validation by relying on
bash-argparsechecking the user's input against the type specification. - Automatic: Rely on
bash-argparsededucing the program's name and short-options.
- Python 3.7 or above
Install it from pip:
pip install bash-argparseOr check the artifacts from the GitHub actions pipelines to download a nightly build.
Here is a basic example:
#!/bin/bash
set -eou pipefail
# accepts 4 options passed to the script (through `$@`)
# * a boolean flag --foo/-f, or --no-foo
# * an integer option --bar <I>/-b<I>
# * and a string option --fuz <S>/-F <S>
# * --help or -h to print the automatic help message
eval $( python3 -m bash-argparse \
--signature "bool foo; int bar; string Fuz" \
--description "This program does many things." \
-- "$@" )
# the variables are set by `eval`
echo $FOO $BAR $FUZbash program.shprintsfalse 0bash program.sh --bar 4printsfalse 4bash program.sh -f --bar 4printstrue 4bash program.sh -f --fuz 'hello'printstrue 0 hello
See the documentation in the doc/ directory
This project is distributed under the MIT License. For more information see the LICENSE file.