resetting the arguments (was: Re: Finding the last arg)

Maarten Litmaath maart at cs.vu.nl
Sat Dec 29 11:51:26 AEST 1990


In article <3074 at wyse.wyse.com>,
	bob at wyse.wyse.com (Bob McGowen x4312 dept208) writes:
)...
)   3)  while [ ! -z "$1" ]
)       do
)	  if [ $# -eq 1 ]
)	  then
)	     last=$1
)	     shift
)	  else
)	     rest="$rest $1"
)	     shift
)	  fi
)       done

How about the following alternative?  It works for `funny' arguments too.

--------------------cut here--------------------
#!/bin/sh
# find the last argument AND reset all arguments but the one found,
# using only BUILTIN constructs

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
--
nlp at berlin.mt.cs.cmu.edu: "I heard that an Awk was spotted in Sherwood forest."
rmk at frog.UUCP (Rick Kelly): "It was seen running in the background."



More information about the Comp.unix.shell mailing list