这个代码说明 for 是先计算需要分配多少个坑(不检查是否重复),然后再往对应的坑里填内容 | @@echo off | | :::this prints - 1:[i] 2:[] 3:[] 4:[] 5:[] 6:[] 7:[] | | for /f "tokens=1,1,1,1,1,1,1" %%a in ("i ii iii iv v vi vii") do ( | | @echo 1:[%%a] 2:[%%b] 3:[%%c] 4:[%%d] 5:[%%e] 6:[%%f] 7:[%%g] | | ) | | | | :::this prints - 1:[i] 2:[ii] 3:[iii] 4:[iv] 5:[] 6:[] 7:[%g] | | for /f "tokens=2,3,1-4" %%a in ("i ii iii iv v vi vii") do ( | | @echo 1:[%%a] 2:[%%b] 3:[%%c] 4:[%%d] 5:[%%e] 6:[%%f] 7:[%%g] | | ) | | | | :::this prints - 1:[i] 2:[ii] 3:[iii] 4:[] 5:[] 6:[] 7:[%g] | | for /f "tokens=1-3,1-3," %%a in ("i ii iii iv v vi vii") do ( | | @echo 1:[%%a] 2:[%%b] 3:[%%c] 4:[%%d] 5:[%%e] 6:[%%f] 7:[%%g] | | ) | | | | exit /b 0 | | http://stackoverflow.com/questions/25950181/why-for-f-sets-empty-values-for-repeated-numbers-in-the-rest-of-tokensCOPY |
这个特性好玩 |