There are so many ways to pass/parse command-line arguments in bash. Currently, I have a rather basic approach for parsing this: parse.sh -a -b VALUE
:
while getopts "ab:c:d" opt; do
# Do something with the arguments
...
done
More examples:
parse.sh -a -b VALUE -d
parse.sh -a -c VALUE -d
But my simple approach does not handle more complex use cases like:
parse.sh --hostname -a -b VALUE -c VALUE /path/to/file.txt
parse.sh -c -a VALUE -b --verbose
parse.sh /path/to/file.txt
It would be nice if there is a standard drop in framework which someone could use to parse arguments in bash rather than trying to handle arg parsing themselves. I've searched around on Google but can't seem to find such a framework. Does anyone know if such a framework exists?