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-12 15:43
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Blank lines and labels (that is, lines starting with : or ::) cannot be used consecutively at the same time inside () View 1,334 Replies 6
Original Poster Posted 2009-09-03 01:29 ·  中国 吉林 延边朝鲜族自治州 电信
银牌会员
★★★
正在学习中的菜鸟...
Credits 1,039
Posts 897
Joined 2009-03-01 15:34
17-year member
UID 140302
Gender Male
From 在地狱中仰望天堂
Status Offline
Inside (), blank lines and labels (that is, lines starting with : or ::) cannot be used consecutively at the same time


Running the following batch file gives the error “The command syntax is incorrect”; if you remove the blank line or the :: line, it runs normally:
for /l %%i in (1 1 9) do (
echo %%i

::注释
)
pause



Running the following batch file gives the error “The command syntax is incorrect”; if you remove the blank line or the : line, it runs normally:
for /l %%i in (1 1 9) do (
echo %%i

:标签
)
pause



Why is that?

[ Last edited by Hanyeguxing on 2009-9-3 at 02:50 ]
Floor 2 Posted 2009-09-03 01:54 ·  中国 吉林 延边朝鲜族自治州 电信
银牌会员
★★★
正在学习中的菜鸟...
Credits 1,039
Posts 897
Joined 2009-03-01 15:34
17-year member
UID 140302
Gender Male
From 在地狱中仰望天堂
Status Offline
Floor 3 Posted 2009-09-03 02:08 ·  中国 广东 东莞 电信
银牌会员
★★★
批处理编程迷
Credits 1,916
Posts 752
Joined 2008-12-28 04:30
17-year member
UID 135147
Gender Male
From 广西
Status Offline
:labels, when placed inside compound code blocks, are inherently meaningless to batch files,
so it should be normal that they can't run;
if they can run, that would instead be a bug in cmd
精简
=> 个人网志
Floor 4 Posted 2009-09-03 02:12 ·  中国 吉林 延边朝鲜族自治州 电信
银牌会员
★★★
正在学习中的菜鸟...
Credits 1,039
Posts 897
Joined 2009-03-01 15:34
17-year member
UID 140302
Gender Male
From 在地狱中仰望天堂
Status Offline
Originally posted by netbenton at 2009-9-3 02:08:
: Labels, when placed inside a compound block, are inherently meaningless to batch files,
so it's normal if they can't run; if they can run, then that's actually a bug in cmd


But without a blank line, it can run.
It's just that labels and blank lines can't be used inside () at the same time; used separately, either one still works.
Besides, the command-line syntax doesn't specify anything like that either.

[ Last edited by Hanyeguxing on 2009-9-3 at 02:49 ]
Floor 5 Posted 2009-09-03 08:42 ·  中国 江西 赣州 电信
银牌会员
★★★★
Credits 2,025
Posts 1,122
Joined 2007-09-05 20:15
18-year member
UID 96653
Gender Male
Status Offline
It just isn't allowed to be used that way, I guess, so it gives the prompt “The command syntax is incorrect.”

I tried AutoHotkey too, and it can't be used this way either. Code:
{
msgbox 1
goto 3
msgbox 2
3:
}

After running it, the prompt is:
Error: A label must not point to the end of a block. For loops, use Continue vs. Goto.
Floor 6 Posted 2009-09-09 12:34 ·  中国 陕西 西安 电信
银牌会员
★★★★
钻石会员
Credits 2,278
Posts 1,020
Joined 2007-11-19 13:34
18-year member
UID 103127
Gender Male
Status Offline
I've been working with batch files for ages, but actually there are still a lot of things about cmd preprocessing that I don't dare dig into deeply, just like pointers and memory management in C; subconsciously I always avoid them...

But it's exactly these so-called “bugs” that make cmd more interesting in an invisible way. If used properly, they can achieve a lot of strange functions. Just like malformed directories, we're happy to accept them too.
山外有山,人外有人;低调做人,努力做事。

进入网盘(各种工具)~~ 空间~~cmd学习
Floor 7 Posted 2010-04-14 22:51 ·  中国 重庆 电信
新手上路
Credits 14
Posts 9
Joined 2010-01-15 11:13
16-year member
UID 158705
Gender Male
Status Offline
It really is like that too... can't figure it out
Forum Jump: