Ksh riddle: interpret variable two times?

exam is a ksh script. In command line I enter: exam 3 param_2 param_3 param_4.

In exam how can I get the value of the parameter which position is specified by the first argument.
Simply doing this DOES NOT work:

offset=$1
value=$$offset

can you figure out any possible way to interpret a variable two times

Check out the "shift" command. I think it will do what you are looking for.

Try:
eval value=\$$offset

An alternative to shifting the parameters down would be: (oops, posted at same time - gotta be fast to beat Perderabo, even this early in the morning! :smiley: )

eval myparm=$"$1"

I'd like to correct: last one is not the same!
I've tryed it:

bash-845:/home/dca0701/develop/src> nn=aa
bash-846:/home/dca0701/develop/src> aa=final
bash-851:/home/dca0701/develop/src> eval dn=\$$nn
bash-852:/home/dca0701/develop/src> echo $dn
final
bash-853:/home/dca0701/develop/src> eval dn=$"$nn"; echo $dn
aa

I do not even understand why it is happened this way?!
First time by 'eval' the $nn should be substituted for 'aa' and '"' should be remuved (as I understand!). So result should be

dn=$aa

and that by next processing should be as expected! But it prints only aa ?!
-------------------------
Ok, I've get it! It should be little bit different:

eval dn="$"$nn; echo $dn

Now it is going to result the same!

So: the 'eval' do NOT evaluates value in double quotations or after backslash, but removes that quotations and backslashes!

>So: the 'eval' do NOT evaluates value in double quotations or after backslash, but removes that quotations and backslashes!

Not exactly. Remember, the shell parses the entire line one time before "eval" gets to interpret it. Walking through:

The original line looks like this:

eval dn="$"$nn; echo $dn

after the shell parses it one time, it looks like this:

eval dn=$aa; echo final

Since the value of $aa is "final", thats what gets assigned to dn. But notice that $dn already had a value from a previous statement, and it was that value which got expanded into the literal string "final" before eval interpreted the code.

Also note that "$" evaluates to a literal dollar sign, because there is no way the shell can construe it as a variable indicator

further details on my wiki...