Subject: bin/2505: /bin/sh and $OPTIND
To: None <gnats-bugs@NetBSD.ORG>
From: None <>
List: netbsd-bugs
Date: 06/03/1996 10:47:00
>Number:         2505
>Category:       bin
>Synopsis:       OPTIND set wrong
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Jun  3 05:20:01 1996
>Originator:     Wolfgang Schludi
	marco GmbH, Dachau, Germany
>Release:        960530
System: NetBSD tabatha 1.1_ALPHA NetBSD 1.1_ALPHA (ROBIN) #0: Mon Nov 6 16:27:59 MET 1995 leo@robin:/usr/src/sys/arch/i386/compile/ROBIN i386
	If getopts parses an option which requires an argument,
	OPTIND is incremented even if the argument is appended
	to the option (without space).
	$ cat <<'EOT' >exam
		while getopts "dl:am?" option; do
			case "$option" in
			d)	DEBUG=true ;;
			l)	LANG=$OPTARG ;;
			a)	LAM=false ;;
			m)	LA=false ;;
			?)	exit 1 ;;
		shift `expr $OPTIND - 1`
	$ /bin/sh exam -l D
	$ /bin/sh exam -lD
	shift: can't shift that many
	ham mer net