Create a Bash Script that Accepts Named Options with getopts

InstructorCameron Nokes

Share this video with your friends

Send Tweet

Let’s say you want to allow a user to pass a -v flag to turn on verbose logging in a script. Manually parsing out options passed to a script is difficult, but in this lesson, we’ll learn about getopts which makes it easy. We'll look at the limitations of using getopts (options must be in a format like -a or -ab <value>) as well as the importance of shifting processed options off of the argument array.

Joseph
~ 5 years ago

Does getopt support case sensitivity? Is -a equal to -A?

Cameron Nokesinstructor
~ 5 years ago

Does getopt support case sensitivity? Is -a equal to -A? It does support case sensitivity, -a != -A. I updated the footnotes for this lesson (https://github.com/ccnokes/advanced-bash-automation-for-web-developers/tree/master/12-getopts) with that 👍.