getopts

Official Description

Parses command-line options (such as -x).

Syntax

getopts optstring
					name [arg...]

Options

None

Oddities

Can be flaky. I've had some incompatibilities with the Bourne shell in the past—none recently, though.

Example

Chapter 13, “Pulling It All Together,” has an example of using getopts.

Get Korn Shell Programming by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.