Splitting content of env var in for loop

Microsoft Windows professional 2000
October 26, 2009 at 05:06:29
Specs: Windows 2000
I have a variable containing some words separated by one space, like this

set VAR=word1 word2 word3

Is it possible to have a FOR loop which loops over the word? Something similar in spirit to

rem call mybatch word1
rem call mybatch word2
rem etc.
for %%i in (%VAR%) do call mybatch %%i

only that written in this way, it's syntactically not valid.


See More: Splitting content of env var in for loop

Report •


#1
October 26, 2009 at 05:36:55
@echo off & setLocal EnableDELAYedExpansion

set VAR=word1 word2 word3

for /f "tokens=1-3 delims= " %%a in ("!VAR!") do (
call mybatch %%a
call mybatch %%b
call mybatch %%c
)


=====================================
Helping others achieve escape felicity

M2


Report •

#2
October 27, 2009 at 05:25:29
This did not work. For example, executing the following Batch file:

@echo off
setlocal ENABLEDELAYEDEXPANSION
set PROD_DIRNAME_IALL=I1 I2
for %d in (%PROD_DIRNAME_IALL%) do echo xxx %%d

produces the error message

"PROD_DIRNAME_IALLd" ist syntaktisch an dieser Stelle nicht verarbeitbar.

which means that there is a syntax error in the FOR statement.


Report •

#3
October 27, 2009 at 22:30:53
"This did not work"

%d should be %%d


=====================================
Helping others achieve escape felicity

M2


Report •

Related Solutions

#4
October 28, 2009 at 06:08:42
Indeed - thanks a lot!!!!!

Report •


Ask Question