Using Shell Script Options with getops
Often, an administrator will need to pass both arguments and options to a shell script. That’s easily done by passing positional parameters to the script, as we’ve seen in previous chapters. But, if you need to use normal Linux/Unix-style option switches, and you need to use arguments for certain options, then you’ll need a helper program. In this chapter, I’ll show you how to use getops
to pass options, arguments, and options with arguments to a script.
Topics in this chapter include:
- Understanding the need for
getopts
- Understanding
getopt
versusgetopts
- Using
getopts
- Looking at real-world examples
So, if you’re ready, let’s dig in.