Looking for clarification of getopts specifications for ksh

39 Views Asked by At

Years ago, I found this reference to some details behind advanced use of getopts in KornShell scripts. This is an excellent reference as far as it goes, but looking at some other code from other sources, it is clear that this is not the definitive standard for getopts within KornShell. And, since it's simply an example, much is left to the imagination regarding what can be done here.

Digging deeper, I recently found this Oracle reference that does provide more detail, which I appreciate.

But I have found inclarities in the descriptions.

For example, 'An option argument specification consists of the option argument name as field 1.' Exactly what is an argument name, and how is it used? Another example, same paragraph, is mention of a "type name," but again, I do not find any clarity in what a type name is, and how it is used. Only its title.

Also, where 'An argument specification' is mentioned, there is scant detail about the formatting and use of "option argument values," only stating 'A list of valid option argument values can be specified by enclosing them inside a {...} following the option argument specification. Each of the permitted values can be specified with a [...] containing the value followed by a description.' Here, the mention of brackets and braces is confusing at best, and ambiguous at worst.

I'm not here to put down this excellent documentation - and not interested in doing so. These are great helps to handling probably the bulk of what people want to do with getopts. What I am looking for, is a clear explanation of - especially - these argument specifications and how the list of options can be specified. I've tried a few options like:

USAGE+="[b:is-batch]:[IS_BATCH_ARG:ignorecase:=NO{[YES][NO][Y][N]}]"

The result of the above is this:

OPTIONS
    -b, --is-batch=IS_BATCH_ARG The default value is NO{}

Also, clarity around the other things I mentioned (type name, and an option argument name) would be very helpful for me.

I'm trying to put together a fairly complex script that has a lot of parameters (some yes/no - which might benefit from 'list of values'), and this looks like the ideal tool to complete what's needed - I especially like the automatic --man option! But various combinations of things aren't quite achieving my expectation after reading those pages.

Is there someone reading this who can help me understand how these finer details of the getopts function would be properly implemented, so that I may exploit it to its potential?

Thanks.

0

There are 0 best solutions below