$argv[$#argv]

Martin Weitzel martin at mwtech.UUCP
Tue May 28 09:04:57 AEST 1991


In article <16278 at smoke.brl.mil> gwyn at smoke.brl.mil (Doug Gwyn) writes:
>In article <1991May25.204543.6428 at midway.uchicago.edu> goer at ellis.uchicago.edu (Richard L. Goerwitz) writes:
>>It's not obvious to me how to take the value of the last argv
>>element with /bin/sh, the way one can do with the C-Shell using
>>subscripts.  Perhaps an ignorant question, but how do?

Yes, you're right, it's ignorant - especially ignorant of the FAQ posted
monthly to this group (refer to question #32).

>It's somewhat context sensitive, but here's one example:
>	$ set -- a b c
>	$ echo `eval echo $"$#"`
>	c

But as Doug was already kind enough to post one possible solution, I'll
post another (which happens to be my favorite as it works on ALL flavours
of the bourne shell and with ANY number of arguments):

	for last do :; done

Now the last argument is left in the shell variable last.
-- 
Martin Weitzel, email: martin at mwtech.UUCP, voice: 49-(0)6151-6 56 83



More information about the Comp.unix.questions mailing list