Getop string1 string2 .. the characters marked in nstring1 indicate valid signs (-can be followed by characters). If there are: After the flag, it indicates that this sign is followed (there can be 0-N spaces) stringx is its parameter. getop processes string2 .... n, output result-flag 1 parameter 1-flag 2 parameter 2 ..... -- parameter n
40:/tmp/V> getopt "A: B" "-bafile"
-B-a file --
As you can see, getopt is also the rule of getopts to re-combine parameters.
At this level, they are exactly the same
Note that the difference between them is that the shell that provides getopts has the built-in optarg variable, and getopts has modified this variable.
Getopt cannot. Therefore, getopt must use set to reset the location parameter $1, $2 ....
Then, shift is used in getopt to obtain the data in sequence.
Furthermore
ARGs = 'getopt Abo: $ *'
Set -- $ ARGs
Note that if a parameter contains spaces, the parameter is changed to multiple parameters. Therefore, if the parameter may contain spaces, getopts must be used. Otherwise, there is no difference between them.
Of course, what's important is
Getopt is an external binary file, while getopts is built-in