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-24 14:35
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Question about DOS batch commands!! View 2,172 Replies 3
Original Poster Posted 2002-11-11 00:00 ·  中国 广东 广州 联通
初级用户
Credits 229
Posts 37
Joined 2002-11-09 00:00
23-year member
UID 207
Gender Male
Status Offline
Today I saw a command like this in some DOS books, but I don't understand exactly how it is used, and I don't really understand what it means either. I'd like the experts to give me some guidance!!

1。 The batch file below will repeatedly display the contents of several specified files:
c:\>type demo2.bat
for %%x in (%1 %2 %3 %4) do type %%X
c:\>
What I want to ask is;
1。 %1 %2 %3 %4 are originally parameters of the batch file, so what is the purpose of putting them inside the parentheses in the command above? How do we define the values of its parameters?

And also, I often see expressions like %cdrom%. What do the % signs on both sides mean? Under what circumstances can expressions like these be used? Please give me some guidance...
Floor 2 Posted 2002-11-11 00:00 ·  美国 肯塔基州 费耶特县 列克星敦 Charter_Communications
系统支持
★★★★★★
“新DOS时代”站长
Credits 27,736
Posts 10,521
Joined 2002-10-09 12:00
23-year member
UID 9
Status Offline
The % signs on both sides of cdrom indicate that it is an environment variable. That command means to display the contents of the files corresponding to the parameters entered as %1, %2, %3, and %4 when executing the batch file. For example, when you run DEMO2 *.TXT *.DOC *.BAT, it will automatically display the contents of those files.
Wengier - 新DOS时代

欢迎大家来到我的“新DOS时代”网站,里面有各类DOS软件和资料,地址:
http://wendos.mycool.net/

E-Mail & MSN: wengierwu AT hotmail.com (最近比较忙,有事请联系DOSroot和雨露,谢谢!)

Floor 3 Posted 2003-12-13 00:00 ·  中国 广东 广州 教育网
铂金会员
★★★★
C++启程者
Credits 5,154
Posts 1,827
Joined 2003-07-18 00:00
22-year member
UID 7105
Gender Male
Status Offline
Actually, parameters can also be layered within parameters!
It can be done like this: for example, a batch file named
"ab.bat"
@echo off
for %%a in (%1 %2 %3 %4) do type %%a
can be run like this:
c:\>ab 1.txt 2.txt 3.txt 4.txt

It also works directly on the command line
c:\>for %a in (%1 %2 %3 %4) do type %a 1.txt 2.txt 3.txt 4.txt
Floor 4 Posted 2005-10-27 13:32 ·  中国 山西 运城 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re gotomsdos:

The command-line usage in post #3 is incorrect. On the command line, %1 and the like, which are command-line parameters used specifically for batch files, will not be parsed and escaped, thus causing the Type command's multiple-parameter error. Even though type in NT CMD can already allow multiple parameters, there would still be a syntax error because %1 cannot be recognized.
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Forum Jump: