Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

$# , ${#}, variable substituition question

SOLVED
Go to Solution
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
Acclaimed Contributor Acclaimed Contributor

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]}
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
Acclaimed Contributor Acclaimed Contributor

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

>is that a download job?

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

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

gotcha - thks
Quod sum eris