Path: utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!samsung!uunet!zephyr.ens.tek.com!tektronix!nosun!qiclab!onion!jeff From: jeff@onion.pdx.com (Jeff Beadles) Newsgroups: comp.unix.shell Subject: Re: Finding the last arg Keywords: Bourne shell arguments Message-ID: <1990Dec27.060903.1604@onion.pdx.com> Date: 27 Dec 90 06:09:03 GMT References: <18476@shlump.nac.dec.com> Lines: 40 In <18476@shlump.nac.dec.com> lan_csse@netrix.nac.dec.com writes: ... >The problem is that I can't figure out any Bourne-shell expression that >gives the last argument. ... >Any ideas? Well, there's nothing that I am aware of in /bin/sh that will ALWAYS allow this to work. The problem is that if you have more than 9 arguements, you have to shift them off to get to what you want. Here's one try that might be of use: #!/bin/sh if [ $# -gt 0 -a $# -lt 10 ] ; then LAST=`eval echo \\$$#` ## 1-9 == Great! elif [ $# -le 0 ] ; then LAST="NO_ARGS" ## 0 == Oops! None! else LAST="TOO_MANY_ARGS" ## >9 == Oops! Too many! fi echo "LAST= >$LAST<" exit 0 However, this is not all that swift. "foo a b c d e f g h i j k" won't work with this. The only other hope is to save off the arguements and loop until the end. This has the possibility of screwing up any special characters and/or white space though, and is generally not-so-hot. -Jeff -- Jeff Beadles jeff@onion.pdx.com