Thanks for the advice guys. If I use SHIFT, won't that shift the rest of my inputs away. Meaning I will lose them. I was hoping to process the command line inputs without having to store them anywhere other than the $0-$9.
The last parameter ($#) is the value at which I need to process the rest of the inputs with. I was hoping to get this value first without having to go through the others.
Thanks again for all the help. I'll try storing the inputs elsewhere.
I didn't know this is why is why you get the star:
eval last_arg=\$$#
echo $last_arg
this successfully works on my Solaris 7 and Red 7.1 systems.
mdn:
You're correct about shift. If you have 9 or less arguments, using Nate's solution works as well my function. Neither solution forces you to store your aguments before finding the last one.
The awk solution is a great idea but can't take arguments with space characters easily.
The eval solution can take arguments with space characters , i.e. a b "c d" e "f g". Sadly, the number of arguments is limited depending on OS (i.e. 10).
Situations with greater than 10 arguments and arguments with space characters need another solution (c, perl, etc...) Cheers,
ND
I know we've probably beat this thread to death, but if you're running the new korn shell, ksh93, (on Solaris it's referred to as the dest top ksh), according to
Bolsky in his book, the New Kornshell
"${@}" is all positional parameters from 1 on
"${@:3}" is all the positional parameters from 3 on
"${@:3:7}" is all the positional parameters from 3 to 7
I thought I'd see what happens using the argument count, $#:
#!/usr/dt/bin/dtksh
# give me the last argument
echo "${@:$#}"
It works; you don't have to eval or worry about shifting if you're argument count
is over 9.
There's always more than one way of doing things. Too bad some of us have to worry
about portability.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.