中国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-18 09:50
47,814 topics / 349,907 posts / today 0 new / 48,259 members
DOS批处理 & 脚本技术(批处理室) » Question about DOS batch commands!!
Printable Version  2,364 / 3
Floor1 copy114 Posted 2002-11-11 00:00
初级用户 Posts 37 Credits 229
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...
Floor2 Wengier Posted 2002-11-11 00:00
系统支持 Posts 10,521 Credits 27,736
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.
Floor3 GOTOmsdos Posted 2003-12-13 00:00
铂金会员 Posts 1,827 Credits 5,154
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
Floor4 willsort Posted 2005-10-27 13:32
元老会员 Posts 1,512 Credits 4,432
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.
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023