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-06-27 03:26
中国DOS联盟论坛 » DOS疑难解答 & 问题讨论 (解答室) » [Help] Experts, please help! Batch file question? View 780 Replies 3
Original Poster Posted 2003-12-31 00:00 ·  中国 联通
初级用户
Credits 116
Posts 3
Joined 2003-11-29 00:00
22-year member
UID 13551
Gender Male
Status Offline
I recently read some articles about batch files, and there are many things I don't understand. I sincerely ask the experts for guidance.
FOR /F %variable IN (file-set) DO command
FOR /F %variable IN (string) DO command
FOR /F %variable IN ('command' DO command
eol=c - specifies the end of a line comment character (only one)
skip=n - specifies the number of lines to skip at the
beginning of the file.
delims=xxx - specifies the delimiter set. This replaces the
default delimiter set of spaces and tabs.
tokens=x,y,m-n - specifies which token on each line is passed to
the for itself for each iteration. This causes
additional variable names to be allocated. The m-n
format is a range. It specifies the mth through nth
tokens. If the last character in the
token string is an asterisk,
then an additional variable will be allocated
and will receive the remaining text of the line
after the last token is parsed.
usebackq - specifies that the new syntax is used in the
following cases:
when executing a back-quoted string as a command, and
a single-quoted character is a literal string command, and
allows double quotes to enclose file names in
filenameset.

There are many things about FOR /F that I don't understand. I hope the experts can give more examples to explain the above parameters.

Floor 2 Posted 2004-01-06 00:00 ·  中国 江苏 连云港 电信
初级用户
Credits 116
Posts 3
Joined 2003-11-29 00:00
22-year member
UID 13551
Gender Male
Status Offline
Why has no one replied to my post?!
Floor 3 Posted 2004-01-07 00:00 ·  中国 天津 教育网
高级用户
★★
Credits 924
Posts 243
Joined 2003-07-09 00:00
22-year member
UID 6612
Gender Male
Status Offline
I really can't understand this part
Floor 4 Posted 2004-01-14 00:00 ·  日本
初级用户
Credits 108
Posts 2
Joined 2004-01-14 00:00
22-year member
UID 15496
Gender Male
Status Offline
This part was translated based on the help text from “for /?” at the command line. It's best to read the original.

I can only explain the general meaning:

eol : specifies what is used as the end marker of a line

skip=n : the for loop starts from line n+1 of the specified file, that is, it skips the first n non-blank lines

delims=xxx : each character in 'xxx' will be treated as a delimiter for tokens (that is, a segment of string),

tokens=x,y,m-n : specifies which tokens will be passed to the %variable variable; if there is more than one parameter after tokens=, then %(variable+1) will be automatically defined, and so on; note that if variable is i, then the next ones automatically defined are j, k, ...

usebackq: uses user-defined syntax; mainly the usage of quotation marks is different. The meaning is as follows:
When not using user-defined syntax, the syntax of for is as follows (note the usage of the various quotation marks)
FOR /F %variable IN (file-set) DO command
FOR /F %variable IN ("string" DO command
FOR /F %variable IN ('command' DO command

If user-defined syntax is used, then the syntax of for is as follows (note the usage of the various quotation marks)
or, if usebackq option present:

FOR /F %variable IN (file-set) DO command
FOR /F %variable IN ('string' DO command
FOR /F %variable IN (`command`) DO command
Forum Jump: