1

Is there any way to ask the user which variable wants to be shown and display it? It should be, as a concept, something like this:

@echo off
set "VAR_1=THIS IS VAR_1"
set "VAR_2=THIS IS VAR_2"
set /p "VAR_TO_SHOW=Enter the variable to show: (VAR_1/VAR_2)"
echo %%VAR_TO_SHOW%%

So if we are in "echo %%VAR_TO_SHOW%%" if we entered "VAR_1" I would want to look like this:

echo %VAR_1%

So the output would be "THIS IS VAR_1". Summarizing all what I've said, I would want to make a variable inside a variable. How can I make this?

Another thing I would want to comment is that I've alredy tried "%%!VAR!%%" and "%%VAR%%" without the exclamation marks, but what is displayied is or "%!VAR_TO_SHOW!%" or the same but without (again) the exclamation marks...

Renk Software
  • 144
  • 2
  • 10

1 Answers1

3
@echo off
set "VAR_1=THIS IS VAR_1"
set "VAR_2=THIS IS VAR_2"
set /p "VAR_TO_SHOW=Enter the variable to show: (VAR_1/VAR_2)"
call echo %%%VAR_TO_SHOW%%%

or

@echo off
setlocal enableDelayedExpansion
set "VAR_1=THIS IS VAR_1"
set "VAR_2=THIS IS VAR_2"
set /p "VAR_TO_SHOW=Enter the variable to show: (VAR_1/VAR_2)"
echo !%VAR_TO_SHOW%!

the second way will work faster.

npocmaka
  • 55,367
  • 18
  • 148
  • 187
  • Thank you a lot!! Thank you, as well, for putting two answers in one! PS: I will take the first one, as I undertand it easier :). – Renk Software Mar 17 '16 at 21:58