1.

Solve : dynamic variable name?

Answer»

Hi, I WANT to use a variable with dynamic NAME in DOS batch but DOS interprets the name not the way I expected. For example,

set NUMBER=1
set VAR=TEST%NUMBER%
set %VAR%=NEW
echo %%VAR%%

I expect the output is "NEW" but the actual output is "%VAR%". Is there any way to solve it?

THANK you.


Sometimes expectations exceed reality. Apparently the command interpreter does not want to see things your way!

Code: [Select]
set NUMBER=1
set VAR=TEST%NUMBER%
set %%VAR%%=NEW


This is all well and fine until you try to use %var%. If you run a SET command after running the code above, you'll see that %var% does indeed have a value of NEW. Due to the fact % SYMBOLS have special meanings to the interpreter, there is probably no way to GET it out of the environment.

Good luck. Thanks! I guess I will not have luck with this. I'm looking to perl or other scripting languages.



Discussion

No Comment Found