While I am making another simple Batch game, I got stuck with this (game is unimportant):
I want a code that gets first N values of a space delimited input and stores them in variables. From my intuition, this should work:
Code: Select all
@echo off
setlocal enabledelayedexpansion
set "Input=A B C D E F G"
for /l %%A in (1,1,4) do (
set "G=%%A"
for /f "tokens=!G! delims= " %%B in (%Input%) do (
set "X_%%A=%%B"
)
)
set X_
::I expect A, B, C, D will be "catched"
pause
But the output gives:
Sample.bat wrote:!G! delims= " was unexpected at this time.
!G! delims= " was unexpected at this time.
!G! delims= " was unexpected at this time.
!G! delims= " was unexpected at this time.
Environment variable X_ not defined
Press any key to continue . . .
Again, thanks for helping guys!
Meerkat