KSH script arguments
Jim Webb
jrw at mtune.ATT.COM
Fri Aug 31 04:05:22 AEST 1990
In article <13160 at hydra.gatech.EDU>, gt0178a at prism.gatech.EDU (BURNS,JIM) writes:
> in article <b4CC02oVc3Jx01 at amdahl.uts.amdahl.com>, jonc at uts.amdahl.com (Jonathan Chang) says:
> > How can I extract the last argument to a ksh script?
>
> I'll answer your question 2 different ways.
....and then takes 60 lines to do it. A bit long winded :-)
And in article <858 at iiasa.UUCP>, wnp at iiasa.AT (wolf paul) writes:
> This works; whether it is the most elegant solution I don't know:
>
> LASTARG=$(eval "echo \$$#")
>
> Anyone know of a better way?
Almost. You have to be careful if you have more than 9 arguments....
$ set a b c d e f g h i j k l m n o p q r s t u v w x y z
$ eval "echo \$$#"
b6
b6? yup.... it turns into echo $26, which is parsed as ${2}6. To
get around this, one needs some more {}'s:
$ eval echo \$\{$#\}
z
Still, very ugly :-) Any other takers on this one?
Later,
--
Jim Webb "Out of Phase -- Get Help" att!mtune!jrw
"I'm bored with this....Let's Dance!"
More information about the Comp.unix.questions
mailing list