Getopt

Parse command-line arguments from shell scripts

Introduction

Getopt(1) is a program to help shell scripts parse command-line parameters. It is for example included in util-linux (versions upto 2.7.1) for Linux. But, there were some problems with that getopt(1) implementation, as listed in the 'BUGS' section of its man-page:

Additionally, the example in the manual-page does not run correctly (at least not with any bash shell I have tried).

I have written an implementation of getopt(1) to solve some of these problems, while still staying (for all practical purposes) completely compatible with other getopt(1) implementations. It has replaced the old util-linux version, but it should be useful for other Unixes too.

Highlights

Getting it

Getopt is included in util-linux. As this package is installed on nearly all Linux distributions, Linux users will have automatic access to it.

If you are not running Linux, you can download it from the download page.

The Documentation page has several example scripts so you can see how it all works.