http://www.perlmonks.org?node_id=661894


in reply to bash vs perl

Actually it's very easy to use getopts from bash the way you're asking. This example would handle myscript.sh -a -b testval -c anotherval with the options a, b, and c.

while getopts ab:c: FOO do case ${FOO} in a) BAR="somevalue" ;; b) BAR="${OPTARG}" ;; c) BAZ="${OPTARG}" ;; \?) echo "<some help text>" exit 1 ;; esac done

The getopts ab:c: means that it's looking for -a, -b, -c and the colon after the b and the c means it expects a value to be specified for those params.

So, while it's obviously not that difficult, it's also very, very limited and is vastly outstripped by perl modules like Getopt::Long. For example, you can only use single letters for your options. Sure, that's 24 available options which is plenty for most scripts, but what if you wanted to specify something like -min and -max. Suddenly you have to remember what letter you've assigned to what functions and it quickly becomes unwieldly.

Check out my brief Getopt::Long example I posted over here recently.

--
naChoZ

Therapy is expensive. Popping bubble wrap is cheap. You choose.