Understanding getopt versus getopts
The getopt
utility, which has its own executable file, has been around forever, since the early days of Unix. Its big advantage is that it can handle long options. In other words, in addition to feeding it single-letter options, such as -a
or -b
, you can also feed it whole-word options such as --alpha
or --beta
. And, that’s it. That’s really its only advantage.
It also has some disadvantages. The original implementation of getopt
can’t handle arguments that have blank spaces in their text strings. So, for example, if you need to work with a file that has a blank space in its filename, you can’t specify that filename as an argument for a shell script that uses the original getopt
. Also, the getopt
syntax is a bit trickier than that of getopts
, which makes getopts
somewhat easier to use.
At some point in time, I’m not sure when, some random Linux developers decided to create a new implementation of getopt...