Is possible to use getopts
to force the user that run the script, to add the options?
I am not asking how to make an option to require a parameter (done with the :
after the option), but how to actually tell the user that he need to add the -something when running the script.
Something like myscript.sh -f FILENAME
; and if the user run the script as myscript.sh FILENAME
he will get an error because he didn't add the -f
option.
As now I check if $1
is empty or not, to print the usage message; and another statement to check if the -f
option is in what the user passed; although if you have 10 options, you add 10 conditional statements? That feels a bit off and not efficient.
Once again, I am not asking how to handle getopts
parameters, but the options themselves. I think the question is pretty clear to show that this has nothing to do with the answer mentioned as possible duplicate of this question.