![]() |
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-07 17:41 |
48,041 topics / 350,128 posts / today 3 new / 48,252 members |
| DOS批处理 & 脚本技术(批处理室) » [Help] Question about ECHO |
| Printable Version 704 / 4 |
| Floor1 simplenoughappy | Posted 2008-03-04 16:54 |
| 初级用户 Posts 19 Credits 42 | |
|
@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 ] |
|
| Floor2 abcd | Posted 2008-03-04 17:19 |
| 银牌会员 Posts 739 Credits 1,436 | |
|
There was no need to add so many spaces
|
|
| Floor3 suntb | Posted 2008-03-04 17:20 |
| 高级用户 Posts 277 Credits 581 | |
|
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 |
|
| Floor4 simplenoughappy | Posted 2008-03-04 17:29 |
| 初级用户 Posts 19 Credits 42 | |
|
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... |
|
| Floor5 pooronce | Posted 2008-03-04 18:10 |
| 中级用户 Posts 250 Credits 484 | |
|
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 |
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |