![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-08-12 13:41 |
47,811 topics / 349,897 posts / today 0 new / 48,256 members |
| DOS学习入门 & 精彩文章 (教学室) » What is the difference between `for %i` and `for %a`? |
| Printable Version 4,735 / 22 |
| Floor1 yemailu | Posted 2007-09-23 19:42 |
| 初级用户 Posts 21 Credits 53 | |
|
Under what circumstances should we use %a, and when should we use %i or %k, etc.?
|
|
| Floor2 gameyixiu | Posted 2007-09-23 21:50 |
| 初级用户 Posts 18 Credits 47 | |
|
Both "i" and "a" are among the 26 English letters. In FOR, they are both variables with no difference. Unless it's FOR /L, where "L" is different, it's an extended command.
|
|
| Floor3 yemailu | Posted 2007-09-24 10:29 |
| 初级用户 Posts 21 Credits 53 | |
|
Is it saying that for %a in (3.txt) do find "2008" %a and for %i in (3.txt) do find "2008" %i are the same?
|
|
| Floor4 Xdao | Posted 2007-09-25 14:45 |
| 新手上路 Posts 7 Credits 19 | |
|
for %a in (3.txt) do find "2008" %a and for %i in (3.txt) do find "2008" %i
They are the same |
|
| Floor5 zhanfu86 | Posted 2007-10-11 12:53 |
| 新手上路 Posts 8 Credits 12 | |
|
Sweat. It's just a variable. Custom - defined.
|
|
| Floor6 hizebra | Posted 2007-10-11 17:43 |
| 新手上路 Posts 5 Credits 19 | |
|
In ordinary applications of for, %a, %i, and %k are not essentially different. Only one variable is sufficient to refer to a group of files, directories, or number sequences, and multiple variable symbols will not appear simultaneously in the for statement.
But when parsing file groups using the /f parameter, the delims and tokens keywords in the "options" parameter define multiple groups of characters, and multiple variables must be used to represent them in sequence. So we often see multiple variable symbols in the for /f statement, and then there is a difference between using %a or %i. First, let's look at a piece of help information about for /f variables: "%i is specifically explained in the for statement, and %j and %k are specifically explained through the tokens= option. You can specify up to 26 symbols in a tokens= line, as long as you don't try to explain a variable higher than the letter 'z' or 'Z'. Remember that FOR variables are single letters, case-sensitive, and global; and at the same time, no more than 52 can be in use." Here it is mentioned that only 26 symbols can be defined, that is, at most 26 variable symbols can appear in the for /f statement. If the first variable is defined as %a, the second is %b, and so on, the last one is %z, and the total number of variables is 26; while if the first variable is defined as %i, the second can only be %j, and the last one is still %z, but the number of definable variables is reduced by 8, leaving only 18. The following example can intuitively show the difference: If the format of the 3.txt file is as follows: 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30 Then for /f "tokens=1-30 delims=," %a in (3.txt) do echo a%,%z will see 1,26, while for /f "tokens=1-30 delims=," %i in (3.txt) do echo i%,%z will see 1,18 (numbers after 18 cannot be defined). [ Last edited by hizebra on 2007-10-11 at 05:53 PM ] |
|
| Floor7 lxmxn | Posted 2008-01-06 00:48 |
| 版主 Posts 4,938 Credits 11,386 | |
It is mentioned here that only 26 symbols can be defined, that is, at most 26 variable symbols can appear in the for /f statement. There are definitely more than 26 symbols: |
|
| Floor8 edisonvon | Posted 2008-01-07 14:05 |
| 新手上路 Posts 5 Credits 10 | |
|
What you said is really detailed
|
|
| Floor9 DarksKy1984 | Posted 2008-01-07 19:28 |
| 初级用户 Posts 24 Credits 46 | |
| Floor10 haiou327 | Posted 2008-01-14 17:42 |
| 高级用户 Posts 348 Credits 713 | |
|
There is not much difference,
Just the DO front and back variables need to be consistent |
|
| Floor11 killkk | Posted 2008-10-07 01:55 |
| 初级用户 Posts 39 Credits 61 From come from hb--wh | |
| Floor12 huytao0915 | Posted 2008-11-06 16:47 |
| 新手上路 Posts 1 Credits 1 | |
Originally posted by lxmxn at 2008-1-6 00:48: Is it according to the increasing order of ASCII codes? |
|
| Floor13 iyou | Posted 2008-11-10 15:48 |
| 新手上路 Posts 20 Credits 18 | |
|
There is not much difference. Just when using for /f, %a is used to receive the lower segment character and %b is used, and %i is used to receive with %j.
|
|
| Floor14 wishpopo | Posted 2008-11-10 22:09 |
| 新手上路 Posts 20 Credits 18 | |
|
Of course it's the same.
The following is the introduction under the command prompt: FOR %%variable IN (set) DO command [command-parameters] %%variable specifies a single letter replaceable parameter. (set) specifies one or a group of files. Wildcards can be used. command specifies the command to be executed for each file. command-parameters specifies parameters or command line switches for a specific command. |
|
| Floor15 zhxy9804 | Posted 2008-11-11 13:47 |
| 中级用户 Posts 97 Credits 208 | |
|
Can you explain the meaning of the code on the seventh floor? I can't understand it. Thanks!
![]() |
|
| 1 2 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |