1
votes

I've spent a while reading through http://ss64.com/nt/for_cmd.html, going through various other questions, and trying a lot of different little command-line variations of the examples, but still haven't gotten a simple for loop task down yet.

Basically, I want to do something where the command is something like

FOR /f %%G in ("1 2 7 16 21 26 688") do(
    echo %%G
)

The output I want to get is

1
2
...
688

But all I get is

1

And then it exits. Through experimenting with various arguments (i.e. have tried "tokens=*", echo %%G echo %%H, "delims= "), nothing gets the desired output. Rather, I get stuff like

1 2 7 ... 688

or

1 %H
1
/f is (basically) for processing files (or command outputs). To process elements (a list), use for without /f - Stephan

1 Answers

1
votes

Try it like this way with a batch file :

@echo off
FOR %%G in (1 2 7 16 21 26 688) do (
    echo %%G
)
pause>nul