Is it possible to use getopts to process multiple options together? For example, myscript -iR or myscript -irv.
Also, I have a situation where based on a condition script would need mandatory option. For example, if argument to script is a directory, I will need to specify -R or -r option along with any other options (myscript -iR mydir or myscript -ir mydir or myscript -i -r mydir or myscript -i -R mydir), in case of file only -i is sufficient (myscript -i myfile).
I tried to search but didn’t get any answers.
You can concatenate the options you provide and
getoptswill separate them. In yourcasestatement you will handle each option individually.You can set a flag when options are seen and check to make sure mandatory "options" (!) are present after the
getoptsloop has completed.Here is an example:
This represents a complete reference implementation of a
getoptsfunction, but is only a sketch of a larger script.