for statement > tokens issue

时间:2017-12-18 06:44:12

标签: batch-file

I want to create a command in my own command prompt that runs a command.

So I set a sample variable. Here it is:

set m=sample -gtc new -args sample

So I tried using for in order to get the command after -gtc and after -args.

So this is my for command:

for /f "tokens=3,5" %%e in ("%m%") do echo %%e

The command responded. But it only responded like tokens=3 meaning the command only echo-ed the one after -gtc not including the -args.

I followed the way https://ss64.com/nt/for_cmd.html said.

tokens=2,4,6 will cause the second, fourth and sixth items on each line to be processed

So the same way what will happen in my command right? It's just like this.

tokens=3,5 will cause the third and fifth items on each line to be processed

1 个答案:

答案 0 :(得分:2)

To use readObject with multiple tokens, the fetched tokens are stores in subsequently FOR /F variables.

In your case FOR /F The first token at position 3 is stored in for /f "tokens=3,5" %%e in ("%m%") do echo %%e and the second token at position 5 is stored in %%e