Name
getopts
Synopsis
getoptsstringname[args]
Process command-line arguments (or args,
if specified) and check for legal options. getopts is used in shell script loops and
is intended to ensure standard syntax for command-line options.
Standard syntax dictates that command-line
options begin with a -.
Options can be stacked; i.e., consecutive letters can follow a
single -. End processing of
options by specifying - - on the command line.
string contains the option letters to be
recognized by getopts when
running the shell script. Valid options are processed in turn and
stored in the shell variable name. If an option
character in the options string is followed by a colon, the actual
option must be followed by one or more arguments. (Multiple
arguments must be given to the command as one shell
word. This is done by quoting the arguments or
separating them with commas. The application must be written to
expect multiple arguments in this format.) getopts uses the shell variables OPTARG,
OPTIND, and OPTERR.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access