2017-09-06 223 views
-1

我有一个要求有嵌套变量来创建一个基于环境变量的文件夹。 假设我有变量,如下面windows批处理命令嵌套变量

%ABC_ASIA_LOCATION% 
%ABC_EUROPE_LOCATION% 
%ABC_US_LOCATION% 

,我想通过这个国家像 %ABC_%COUNTRY%_Location%,我如何在Windows批处理命令实现这个

回答

0

则必须在其变量每个可变进%

set "ABC=ABC" 
set "COUNTRY=EUROPE 
set "LOCATION=MUNICH 
echo %ABC%_%COUNTRY%_%LOCATION% 

结果:ABC_EUROPE_MUNICH

或者,如果你只是想Country为变量,保留其余的固定:

echo ABC_%COUNTRY%_LOCATION 

结果:ABC_EUROPE_LOCATION

,或者如果你想整个事情是一个变量(含另一个变量的变量名) ,你必须使用delayed expansion

setlocal enabledelayedexpansion 
set country=EUROPE 
set "ABC_EUROPE_LOCATION=a town in southern Germany" 
echo !ABC_%country%_LOCATION! 

它给你:a town in southern Germany