中国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-09 08:12
47,811 topics / 349,895 posts / today 0 new / 48,253 members
DOS批处理 & 脚本技术(批处理室) » Do these do anything, can they be removed?
Printable Version  735 / 3
Floor1 zwdeee Posted 2008-07-27 19:00
初级用户 Posts 54 Credits 153
@echo off
set a=0
for /f %%a in (你要搜索的文件.txt) do set a=%%a
echo %a%
Does “set a=0” here have no effect at all? Can it be omitted?
Also:
@echo off & setlocal
set a=
for /f "delims=" %%a in (sample.txt) do set a=%%a
echo.%a%
It seems the effect is the same even if “ & setlocal” and “set a=” are removed?
Floor2 HAT Posted 2008-07-27 19:35
版主 Posts 5,017 Credits 9,023
Although variables in batch files do not have to be defined before use, initializing variables is a very good programming habit, hope you keep it!
Floor3 yangzhiyi Posted 2008-07-27 22:50
中级用户 Posts 123 Credits 261
If a batch file uses multiple identical variables then you should keep the initialization.
Floor4 pusofalse Posted 2008-07-28 01:36
银牌会员 Posts 646 Credits 1,604
The initial value of numeric variables is 0.
Below, calculate 2 to the 10th power.
for /l %%a in (1 1 10) do set/a a*=2
echo %a%
It displays 0, because the initial value of a was not changed, so you need to define a beforehand. set a=1 OK, then the result is correct...
Above is one small issue about the initial value.
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023