Variable substitition
Jeff Beadles
jeff at onion.pdx.com
Sun Dec 2 16:43:34 AEST 1990
In <1990Nov30.092424 at cs.utwente.nl> stadt at 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 at onion.pdx.com
More information about the Comp.unix.questions
mailing list