#!/bin/sh
# find the last argument AND reset all arguments but the one found,
# using only BUILTIN constructs
# set -x	# switch on debugging

case $# in
	0)
		echo 'No arguments specified.' >&2
		exit 1
esac

argv=
last=

while :
do
	case $# in
		1)
			last=$1
			break
	esac
	eval i$#=\$1
	argv="$argv \"\$i$#\""
	shift
done

eval set x $argv
shift

echo "last=$last"
echo 'new arguments:'
for i
do
	echo "  $i"
done
