awk computed variable names

Is there a way to do make-style computed variable names in awk? e.g. in make

foo = bar
bar = wocket

I can get "wocket" with

$($(foo))

Alternatively can you list all defined variables in awk?

thanks

Maybe this helps:

> foo=var
> awk 'BEGIN{var="wocket";print '${foo}'}'
wocket

The following code snippet outputs "wooket"

#!/usr/bin/awk -f

BEGIN {
    bar="wooket";
    foo=bar;
}

END { print foo }

Thanks for the reply, but that's not exactly what I'm after. That just assigns "wocket" to bar, copies the value of that to foo, then prints the value of foo.

I was wondering if it's possible to say (as in a makefile)....

  • assign the string "bar" to the variable foo.
  • assign some string value to the variable bar.
  • retrieve the value of a variable (in this case bar), where the name of the variable to retrieve from is specified in another variable (in this case foo).

So writing $($(foo)) accesses the value of a variable whose name is stored in foo.

Klashxx's one is closer to what I need, but it doesn't work if i move the foo=var from the shell into the awk script.

I guess this can't be done in awk. I'll workaround it a different way.
Thanks

there's no 'eval' in awk: FYI