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-07 16:59
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help] Question about ECHO View 702 Replies 4
Original Poster Posted 2008-03-04 16:54 ·  中国 广东 深圳 联通
初级用户
Credits 42
Posts 19
Joined 2008-02-18 15:56
18-year member
UID 110899
Gender Male
Status Offline
@echo off
set a=1
echo %a%
pause
The above statements.... when I run the batch file, it normally displays 1

Then... I changed the above batch file to this:
@echo off
set aDate = %date:~0,-4%
for /f "tokens=1" %%a in ('type "d:\date.txt"^|find "%aDate%"') do set LastDate = "%%a"
echo %LastDate%
pause
It says ECHO is off

Then I changed it back to
@echo off
set a=1
echo %a%
pause
and it still says ECHO is off

.I'm completely confused.... where exactly is the problem?

[ Last edited by simplenoughappy on 2008-3-4 at 05:00 PM ]
Floor 2 Posted 2008-03-04 17:19 ·  中国 香港 腾讯云
银牌会员
★★★
Credits 1,436
Posts 739
Joined 2007-10-11 17:44
18-year member
UID 99469
Gender Male
Status Offline
There was no need to add so many spaces
Floor 3 Posted 2008-03-04 17:20 ·  中国 福建 福州 联通
高级用户
★★
Credits 581
Posts 277
Joined 2006-12-23 05:10
19-year member
UID 74328
Gender Male
Status Offline
set aDate = %date:~0,-4%
This line has spaces in it, try deleting the spaces
set aDate=%date:~0,-4%

Also, "tokens=1" can be removed; by default it takes the value from the first column
Floor 4 Posted 2008-03-04 17:29 ·  中国 广东 深圳 联通
初级用户
Credits 42
Posts 19
Joined 2008-02-18 15:56
18-year member
UID 110899
Gender Male
Status Offline
I just went and changed it.. it's probably because of the spaces...
Thanks for the reminder from the posters above..... I've only just started learning batch files, so there are a lot of things I don't understand
It really feels like it's very strict about spaces...
I used to be in the habit of adding spaces on both sides of the = sign...
Floor 5 Posted 2008-03-04 18:10 ·  中国 上海 黄浦区 电信
中级用户
★★
Credits 484
Posts 250
Joined 2007-06-05 23:33
19-year member
UID 90372
Gender Male
Status Offline
Because the spaces affected the value of the variable, find couldn't find it in the end, so the output of the for statement was empty
When you have echo display an empty variable, that kind of thing happens
Forum Jump: