xref: /dflybsd-src/tools/regression/bin/sh/builtins/getopts1.0 (revision 3e3895bf4584c1562faf4533cbd97026ee6a8dcf)
1*3e3895bfSKrzysztof Piecuch# $FreeBSD: head/bin/sh/tests/builtins/getopts1.0 297752 2016-04-09 16:06:13Z jilles $
23df4d8b0SPeter Avalos
32fdf5231SPeter Avalosprintf -- '-1-\n'
43df4d8b0SPeter Avalosset -- -abc
53df4d8b0SPeter Avalosgetopts "ab:" OPTION
6*3e3895bfSKrzysztof Piecuchprintf '%s\n' "${OPTION}"
73df4d8b0SPeter Avalos
83df4d8b0SPeter Avalos# In this case 'getopts' should realize that we have not provided the
93df4d8b0SPeter Avalos# required argument for "-b".
103df4d8b0SPeter Avalos# Note that Solaris 10's (UNIX 03) /usr/xpg4/bin/sh, /bin/sh, and /bin/ksh;
113df4d8b0SPeter Avalos# ksh93 20090505; pdksh 5.2.14p2; mksh R39c; bash 4.1 PL7; and zsh 4.3.10.
123df4d8b0SPeter Avalos# all recognize that "b" is missing its argument on the *first* iteration
133df4d8b0SPeter Avalos# of 'getopts' and do not produce the "a" in $OPTION.
142fdf5231SPeter Avalosprintf -- '-2-\n'
153df4d8b0SPeter Avalosset -- -ab
163df4d8b0SPeter Avalosgetopts "ab:" OPTION
17*3e3895bfSKrzysztof Piecuchprintf '%s\n' "${OPTION}"
18*3e3895bfSKrzysztof Piecuchgetopts "ab:" OPTION 3>&2 2>&1 >&3 3>&-
19*3e3895bfSKrzysztof Piecuchprintf '%s\n' "${OPTION}"
203df4d8b0SPeter Avalos
213df4d8b0SPeter Avalos# The 'shift' is aimed at causing an error.
222fdf5231SPeter Avalosprintf -- '-3-\n'
233df4d8b0SPeter Avalosshift 1
243df4d8b0SPeter Avalosgetopts "ab:" OPTION
25*3e3895bfSKrzysztof Piecuchprintf '%s\n' "${OPTION}"
26