good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
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.
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.
-- Therapy is expensive. Popping bubble wrap is cheap. You choose. In reply to Re: bash vs perl
by naChoZ
|
|