What is the best way to check the getopts status in bash?

If you absolutely require MAN, then I suggest you don't make it an option parameter, but a positional parameter. Options are supposed to be optional.

If you absolutely require MAN, then I suggest you don't make it an option parameter, but a positional parameter. Options are supposed to be optional. However, if you want to do it as an option, then do: # initialise MAN to the empty string MAN= # loop as rewritten by DigitalRoss while getopts "$OPTSTRING" SWITCH "$@"; do case "$SWITCH" in m) MAN="$OPTARG" ;; esac done # check that you have a value for MAN -n "$MAN" || { echo "You must supply a MAN's name with -m"; exit 1; } Even better, print the usage message before exiting - pull it out into a function so you can share it with the -h option's case.

The getopts builtin returns 1 ("false") when there are no option arguments. So, your while never executes unless you have option arguments beginning with a -. Note the last paragraph in the getopts section of bash(1): getopts returns true if an option, specified or unspecified, is found.It returns false if the end of options is encountered or an error occurs.

The "best" solution is subjective. One solution would be to give default values to those variables that can be set by options.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions