MPE/iX Shell and Utilities Reference Manual, Vol 1

getopt(1) MPE/iX Shell and Utilities getopt(1)
NAME
getopt — external command to parse shell file options
SYNOPSIS
getopt [–c cmdname] optiondesc argument ...
DESCRIPTION
The getopt command is often used in shell scripts to parse command line options. The first
command argument, optiondesc, contains each option letter that is valid in the following com-
mand argument strings. An option letter followed by a colon (:) means that the preceding
option letter requires a further argument (as in –o file).
getopt considers each argument that begins with a a potential option, and prints an error
if it does not find the argument in optiondesc. Scanning for further options stops at the first
argument which does not begin with or with an argument that is ––. In either case, the
options are separated from the rest of the non-option argument strings by a –– string.
The most common construct for using getopt is
set - - $(getopt [-c cmdname] optiondesc "$@")
This may be used inside the
MPE/iX Shell to parse the arguments to a shell script; see sh(1) for
more about the shell.
Options
getopt accepts the following option:
–c cmdname
uses cmdname rather than getopt when displaying error messages.
EXAMPLE
The command:
getopt –c diff befhnmD: –eh –D string file1 file2
which parses the diff command line options, would produce the following output:
–e –h –D string –– file1 file2
The following is a more realistic and complex example of using getopt in a shell script.
Commands and Utilities 1-253