for statement > tokens issue

强颜欢笑 提交于 2020-01-15 10:13:46

问题


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:


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

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



来源:https://stackoverflow.com/questions/47863327/for-statement-tokens-issue

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!