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-08-09 07:08
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Do these do anything, can they be removed? View 733 Replies 3
Original Poster Posted 2008-07-27 19:00 ·  中国 湖北 黄冈 电信
初级用户
★★
Credits 153
Posts 54
Joined 2007-06-20 18:24
19-year member
UID 91903
Gender Male
Status Offline
@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?
Floor 2 Posted 2008-07-27 19:35 ·  美国 惠普HP
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
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!
Floor 3 Posted 2008-07-27 22:50 ·  中国 广东 茂名 电信
中级用户
★★
Credits 261
Posts 123
Joined 2006-06-06 19:23
20-year member
UID 56648
Status Offline
If a batch file uses multiple identical variables then you should keep the initialization.
Floor 4 Posted 2008-07-28 01:36 ·  中国 山东 淄博 联通
银牌会员
★★★
Credits 1,604
Posts 646
Joined 2008-04-13 23:39
18-year member
UID 115804
Gender Male
Status Offline
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.
心绪平和,眼藏静谧,无比安稳的火... Purification of soul...Just a false...^_^
Forum Jump: