中国DOS联盟论坛

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-16 09:35
47,813 topics / 349,903 posts / today 0 new / 48,258 members
DOS疑难解答 & 问题讨论 (解答室) » [Help] Experts, please help! Batch file question?
Printable Version  823 / 3
Floor1 ivan Posted 2003-12-31 00:00
初级用户 Posts 3 Credits 116
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.

Floor2 ivan Posted 2004-01-06 00:00
初级用户 Posts 3 Credits 116
Why has no one replied to my post?!
Floor3 aria Posted 2004-01-07 00:00
高级用户 Posts 243 Credits 924
I really can't understand this part
Floor4 ddy1975 Posted 2004-01-14 00:00
初级用户 Posts 2 Credits 108
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
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023