Getopt

From LQWiki
Jump to navigation Jump to search

Getopt parses a parameters string and outputs it in a normalized format. Imagine you want to write your own bash script foo that takes options. It should be no matter if the user calls it

foo -abcd

or

foo -a -b -c -d

getopt normalizes the parameters:

scorpio:~ # getopt abcd -abcd
 -a -b -c -d --

The first parameter tells getopt which options are allowed (a,b,c and d in this case), the second parameter is the string to be normalized.

Provided by

Most (all?) Linux distributions incorporate this from the [util-linux] project.

See also