blob: 5f255db7f71128eb47ae00591d651bf1f2f4651f [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
Denys Vlasenko007ce9f2017-08-13 02:59:00 +020014(
15
Denys Vlasenko419db032017-08-11 17:21:14 +020016echo "*** optstring:':ac' args:-a -b -c"
17getopts ":ac" var -a -b -c; echo "1 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
18getopts ":ac" var -a -b -c; echo "2 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
19getopts ":ac" var -a -b -c; echo "3 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
20getopts ":ac" var -a -b -c; echo "4 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
21# Previous line should result in "rc:1", which is normally treated
22# in getopts loops as exit condition.
23# Nevertheless, let's verify that calling it yet another time doesn't do
24# anything weird:
25getopts ":ac" var -a -b -c; echo "5 rc:$? var:'$var' OPTIND:$OPTIND OPTARG:'$OPTARG'"
Denys Vlasenko007ce9f2017-08-13 02:59:00 +020026
27) 2>&1 \
28| sed -e 's/ unrecognized option: / invalid option -- /' \
29 -e 's/ illegal option -- / invalid option -- /' \