Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!att!linac!uwm.edu!wuarchive!uunet!zephyr.ens.tek.com!tektronix!nosun!qiclab!onion!jeff From: jeff@onion.pdx.com (Jeff Beadles) Newsgroups: comp.unix.questions Subject: Re: Variable substitition Message-ID: <1990Dec2.054334.10048@onion.pdx.com> Date: 2 Dec 90 05:43:34 GMT References: <1990Nov30.092424@cs.utwente.nl> Lines: 30 In <1990Nov30.092424@cs.utwente.nl> stadt@cs.utwente.nl (Richard van de Stadt) writes: >Is there some sort of variable substitution possible in a shell script >to get the value of the last argument supplied to the script? I don't >mean shifting the arguments until one is left. I'd like to know if something >like awk's $NF, in which NF means the number of fields, and $NF means the >value of the last field, is possible. ${$#} results in an error message. Well, this will work in the bourne shell: #!/bin/sh last="`eval echo \\$$#`" echo "Last field = $last" exit 0 And, when run: % ./t jeff beadles Last field = beadles This might not be the most elegant solution, but it does work. It's even been somewhat tested, :-) -Jeff -- Jeff Beadles jeff@onion.pdx.com