Operating System - HP-UX
1748150 Members
3684 Online
108758 Solutions
New Discussion юеВ

$# , ${#}, variable substituition question

 
SOLVED
Go to solution
Eric Lipede
Frequent Advisor

$# , ${#}, variable substituition question

Hi there
hope you guys had a good x-mas.
I have a small question (i hope).

A snippet of my current script is...

if [ $# -ge 2 ]
then
ARG_NUMBER="$#"
echo "$"$ARG_NUMBER""

it returns -> $4

...how do i get it to return the 4th argument (based on ARG_NUMBER) rather than the number of arguments without EXPLICITlLY saying echo $4 ?

Thks


Quod sum eris
4 REPLIES 4
Dennis Handly
Acclaimed Contributor
Solution

Re: $# , ${#}, variable substituition question

You need to use eval.
Or you can copy the parms to an array:
set -A save -- "$@"
echo ${save[4-1]}
Eric Lipede
Frequent Advisor

Re: $# , ${#}, variable substituition question

sounds good...ive only used eval on solaris and the only reference to it on my 11.23 box is /usr/lib/builtins/eval (and thats empty) ...is that a download job ?
Quod sum eris
Dennis Handly
Acclaimed Contributor

Re: $# , ${#}, variable substituition question

>is that a download job?

eval is a shell builtin. Try:
eval echo "$"$ARG_NUMBER
Eric Lipede
Frequent Advisor

Re: $# , ${#}, variable substituition question

gotcha - thks
Quod sum eris