This chapter started with a recap of how positional parameters are used in Bash. We continued by showing you how most command-line tools we've introduced up until this point (and those we haven't) use flags, often as modifiers for script functionality, whereas positional parameters are used to indicate targets for the commands.
We then introduced a way for the reader to incorporate options and option arguments within their own scripts: by using the getopts
shell builtin. We kicked this off by discussing the differences between the legacy program getopt
and the newer builtin getopts
, which we focused on for the rest of this chapter.
Since getopts
only allows us to use short options (whereas getopt
and some other command-line tools also use long options, denoted by double dashes), we showed you how this is not an issue due to the recognition of common short options such as -h
, -v
, and so on.
We properly introduced the getopts
syntax with a few examples. We showed how you can use flags...