2

I want to use one variable value as another variable name in command line script. e.g:

set VAR1=%1
call set VAR3=JAVA%VAR1%_HOME
echo %VAR3%

This should print the value of system environment variable called JAVA8_HOME (C:\program Files\Java\jdk1.8.0_121)

How can I do it?

Alex K
  • 5,092
  • 15
  • 50
  • 77
  • 1
    Simply use `call echo %%%VAR3%%%` or if delayed expansion is enabled `echo !%VAR3%!` –  Jun 25 '17 at 09:50
  • 2
    This type of management is fully explained at [this answer](https://stackoverflow.com/questions/10166386/arrays-linked-lists-and-other-data-structures-in-cmd-exe-batch-script/10167990#10167990), although the topic is different... – Aacini Jun 25 '17 at 15:48

1 Answers1

2
call set VAR3=%%JAVA%VAR1%_HOME%%

should solve the problem, assuming % and hence var has a value 8.

call set VAR3=%%JAVA%1_HOME%%

should also work in this instance.

Magoo
  • 77,302
  • 8
  • 62
  • 84