China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-12 14:35
中国DOS联盟论坛 » DOS学习入门 & 精彩文章 (教学室) » What is the difference between `for %i` and `for %a`? View 4,742 Replies 22
Original Poster Posted 2007-09-23 19:42 ·  中国 浙江 温州 洞头区 电信
初级用户
Credits 53
Posts 21
Joined 2007-08-03 18:24
19-year member
UID 94588
Gender Male
Status Offline
Under what circumstances should we use %a, and when should we use %i or %k, etc.?
Floor 2 Posted 2007-09-23 21:50 ·  中国 上海 电信
初级用户
Credits 47
Posts 18
Joined 2007-09-08 21:55
18-year member
UID 96891
Gender Male
Status Offline
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.
Floor 3 Posted 2007-09-24 10:29 ·  中国 浙江 温州 洞头区 电信
初级用户
Credits 53
Posts 21
Joined 2007-08-03 18:24
19-year member
UID 94588
Gender Male
Status Offline
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?
Floor 4 Posted 2007-09-25 14:45 ·  中国 山西 大同 电信
新手上路
Credits 19
Posts 7
Joined 2007-09-19 11:47
18-year member
UID 97768
Gender Male
Status Offline
for %a in (3.txt) do find "2008" %a and for %i in (3.txt) do find "2008" %i

They are the same
Floor 5 Posted 2007-10-11 12:53 ·  中国 福建 泉州 惠安县 电信
新手上路
Credits 12
Posts 8
Joined 2006-12-26 15:15
19-year member
UID 74620
Gender Male
Status Offline
Sweat. It's just a variable. Custom - defined.
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
jmsxy1209 +1 2007-12-20 00:27
Floor 6 Posted 2007-10-11 17:43 ·  中国 陕西 汉中 电信
新手上路
Credits 19
Posts 5
Joined 2007-10-10 15:51
18-year member
UID 99367
Gender Male
Status Offline
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 ]
Recent Ratings for This Post ( 3 in total) Click for details
RaterScoreTime
rokersong +1 2007-11-12 11:06
jmsxy1209 +1 2007-12-20 00:27
zhxy9804 +2 2009-10-17 17:51
Floor 7 Posted 2008-01-06 00:48 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
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:
for /f "tokens=1,3,4" %+ in ("hello world batch fans") do @echo %+/%,/%-
Recent Ratings for This Post ( 2 in total) Click for details
RaterScoreTime
luckymistDOS +1 2008-01-07 22:05
ngd +1 2008-01-22 18:34
Floor 8 Posted 2008-01-07 14:05 ·  中国 河南 洛阳 鹏博士宽带
新手上路
Credits 10
Posts 5
Joined 2008-01-06 20:03
18-year member
UID 107838
Gender Male
Status Offline
What you said is really detailed
Floor 9 Posted 2008-01-07 19:28 ·  中国 福建 电信
初级用户
Credits 46
Posts 24
Joined 2008-01-04 22:09
18-year member
UID 107690
Gender Male
Status Offline
Floor 10 Posted 2008-01-14 17:42 ·  中国 广东 汕头 潮阳区 电信
高级用户
★★★
DOS时空
Credits 713
Posts 348
Joined 2007-02-10 13:59
19-year member
UID 79169
Gender Male
Status Offline
There is not much difference,
Just the DO front and back variables need to be consistent
Floor 11 Posted 2008-10-07 01:55 ·  中国 广东 东莞 电信
初级用户
Credits 61
Posts 39
Joined 2007-03-22 16:49
19-year member
UID 82575
Gender Male
From come from hb--wh
Status Offline
Floor 12 Posted 2008-11-06 16:47 ·  中国 江苏 苏州 联通
新手上路
Credits 1
Posts 1
Joined 2008-11-06 15:59
17-year member
UID 130176
Gender Male
Status Offline
Originally posted by lxmxn at 2008-1-6 00:48:


There are definitely more than 26 symbols:
for /f "tokens=1,3,4" %+ in ("hello world batch fans") do @echo %+/%,/%-


Is it according to the increasing order of ASCII codes?
Floor 13 Posted 2008-11-10 15:48 ·  中国 江苏 苏州 电信
新手上路
Credits 18
Posts 20
Joined 2008-11-05 15:36
17-year member
UID 130077
Gender Male
Status Offline
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.
Floor 14 Posted 2008-11-10 22:09 ·  中国 河南 郑州 联通
新手上路
Credits 18
Posts 20
Joined 2008-10-28 22:45
17-year member
UID 129408
Gender Male
Status Offline
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.
Floor 15 Posted 2008-11-11 13:47 ·  中国 山东 临沂 兰山区 电信
中级用户
★★
Credits 208
Posts 97
Joined 2006-12-28 22:08
19-year member
UID 74845
Gender Male
Status Offline
Can you explain the meaning of the code on the seventh floor? I can't understand it. Thanks!
Forum Jump: