blob: 097d7ba85878b75eb4128a70f8fe57cfe085ada3 [file] [log] [blame]
Denys Vlasenko419db032017-08-11 17:21:14 +02001# Open Group Base Specifications Issue 7:
2# """
3# If an unknown option is met, VAR shall be set to "?". In this case,
4# if the first character in optstring is ":", OPTARG shall be set
5# to the option character found, but no output shall be written
6# to standard error; otherwise, the shell variable OPTARG shall be
7# unset and a diagnostic message shall be written to standard error."
8# ...
9# If an option-argument is missing:
10# If the first character of optstring is ":", VAR shall be set to ":"
11# and OPTARG shall be set to the option character found.
12# """
13
14echo "*** optstring:':ac' args:-a -b -c"
15getopts ":ac" var -a -b -c; echo "1 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
16getopts ":ac" var -a -b -c; echo "2 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
17getopts ":ac" var -a -b -c; echo "3 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
18getopts ":ac" var -a -b -c; echo "4 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
19# Previous line should result in "rc:1", which is normally treated
20# in getopts loops as exit condition.
21# Nevertheless, let's verify that calling it yet another time doesn't do
22# anything weird:
23getopts ":ac" var -a -b -c; echo "5 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"