Getopts alternative

Hi,

Does anyone have an example of parsing command line arguments similar to how getopts parse command line arguments?

I am looking at a getopts alternative because I want to have the same parsing on the subroutine/function in the script.

For example, I want to be able to do test.ksh -p 1 -d /tmp but inside the script I want to be able to do do a sub1 -u test01 -o remove.

By using an alternative to getopts, it won't be confusing understanding how I parse argument either from the script or from the subroutines/functions.

Any advice much appreciated. Thanks in advance.

getopts works inside subroutines. Just be sure to set OPTIND to 1 at the beginning of your functions, since this global value may be left at something strange from your last function.

1 Like

Thanks, I will try it out

Assuming you are using the ksh93 version of getopts, you can get the current documentation for it using:

getopts --man

This provides more complete and up-to-date documentation than the ksh manpage.

Hi.

See also post #5 in thread Using getopts for handling multiple options for several different alternatives (in the sense of methods) for parsing arguments ... cheers, drl