freebsd-nq/bin/sh/tests/builtins/getopts10.0
Jilles Tjoelker adba77a62e sh: Ensure OPTIND=1 in subshell without forking does not affect outer env.
Command substitutions containing a single simple command and here-document
expansion are performed in a subshell environment, but may not fork. Any
modified state of the shell environment should be restored afterward.

The state that OPTIND=1 had been done was not saved and restored here.

Note that the other parts of shellparam need not be saved and restored,
since they are not modified in these situations (a fork is done before such
modifications).
2016-01-07 20:48:24 +00:00

12 lines
236 B
Plaintext

# $FreeBSD$
set -- -x arg
opt=not
getopts x opt
r1=$? OPTIND1=$OPTIND opt1=$opt
: $(: $((OPTIND = 1)))
getopts x opt
r2=$? OPTIND2=$OPTIND
[ "$r1" = 0 ] && [ "$OPTIND1" = 2 ] && [ "$opt1" = x ] && [ "$r2" != 0 ] &&
[ "$OPTIND2" = 2 ]