Lion
Lion

Reputation: 81

How to get the env value that itself is a variable?

Suppose I have env variables in windows:

IA=C:\a
IB=C:\b

now I write a batch script:(named s.bat)

@echo off
set var=%1
echo %var%

When I run s.bat IA,the result is IA , but I actually want the result to be C:\a. How can I achieve this requirement?

Upvotes: 3

Views: 55

Answers (1)

jeb
jeb

Reputation: 82307

You can use delayed expansion or the call trick.

@echo off
setlocal EnableDelayedExpansion
set "varname=%1"
echo %varname%
echo !%varname%!  - This works
call echo %%varname%%  - This too

Upvotes: 5

Related Questions