2

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?

mac2017
  • 445
  • 1
  • 6
  • 16
  • 2
    maybe check this qst: http://stackoverflow.com/q/402377/632407 how to handle long options from a bash directly, or this http://unix.stackexchange.com/a/62960/37612 for a "framework". (the framework is `perl` :) – clt60 May 01 '13 at 20:30

0 Answers0