Geopts is a Bash built-in widely used to efficiently parse switches and arguments passed on the command line of a script. We already saw other ways to accomplish this task, but getops makes it quite easy to handle it, since it can automatically recognize the switches and argument passed to the script. Its syntax is as follows:
getops options variable
The first thing we pass to getops is a string of options, the classical -a -x -f of whatever you want, without any leading dash, such as getops axf or also getops ax:f. If you see an option followed by a colon, this means that the option is meant to have an argument such as follows:
./our_script.sh -x our_argument -a
In our example, -x has an argument while -a is a simple switch, or we can also call it flag that can just be there or not, but it does not require any arguments. The options...