Batch variable name in a variable

March 9, 2009 at 00:41:10
Specs: Windows XP
Dear all,

I am having a trouble. I try to use the content of a variable as the name of a variable, in a loop.

When I do the following outside a loop, it works :

SET VAR_1=DONNEE
SET ITR=VAR
SET ACC=%ITR%_1
echo %ACC%   >> access.log
echo !%ACC%! >> access.log

The last line actually prints out the content of VAR_1.

But when I try to put it into a loop it fails since I can not use the '%' character.

FOR /D %%g IN (*) DO (

	SET BROL=%%g
	SET TMP_SCH=!BROL!_SCH
	SET TMP_USR=!BROL!_USR
	SET TMP_PWD=!BROL!_PWD
	
	echo !!TMP_PWD!! >> access.log
	  
)

The last line prints out the name the variable and not its content.

Does anyone have an idea to help me solve this problem ?

Best regards


See More: Batch variable name in a variable

Report •


#1
March 9, 2009 at 01:25:30
I found out : )

FOR /D %%g IN (*) DO (

	SET TMP_PWD=!%%g_PWD!
	echo !TMP_PWD! >> access.log
	  
)


Report •
Related Solutions


Ask Question