Command line operated programs are traditional. They take their arguments from the command line that the program needs to know. Besides arguments, these programs often take command line options as well.
Complicated programs might need not only 'Arguments' but 'Options' too.
For example : A program will be verbose or not.
ksh MyProgram -v true
Or ksh MyProgram -v false
Command line options come in several flavours. Historically, they are preceded by a single dash - , and consist of a single letter.
`-l -a -c`
Usually, these single-character options can be bundled:
`-lac`
Options can have values, the value is placed after the option character ( as shown in the first example or verbose true or false )
`-s 24` OR `-s24`
Due to the very cryptic nature of these options, another style was developed that used long names. So instead of a cryptic -l
one could use the more descriptive --long
. To distinguish between a bundle of single-character options and a long one, two dashes are used to precede the option name. Early implementations of long options used a plus +
instead. Also, option values could be specified either like
--size=24
or
--size 24
The +
form is now obsolete and strongly deprecated.
A very detailed explanation of long getOpts is available at http://perldoc.perl.org/Getopt/Long.html
Note : A note of caution. getopts is note very smart. Users must be aware of it's pitfalls. Though it is meant to make argument processing easier, but it could be error-prone if not used cautiously.