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-01 12:38
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Help]Often when writing batch processing, there is "There should not be goto here at this time" View 2,083 Replies 2
Original Poster Posted 2011-01-15 18:22 ·  中国 黑龙江 哈尔滨 联通
版主
★★
系统收藏家
Credits 326
Posts 285
Joined 2010-02-22 00:00
16-year member
UID 160972
Gender Male
From 黑龙江省
Status Offline
Often such problems occur. Why do they occur? And how to solve them?
Floor 2 Posted 2011-01-15 22:35 ·  中国 吉林 延边朝鲜族自治州 电信
银牌会员
★★★
正在学习中的菜鸟...
Credits 1,039
Posts 897
Joined 2009-03-01 15:34
17-year member
UID 140302
Gender Male
From 在地狱中仰望天堂
Status Offline
1. A single `goto` alone will not cause such a problem.

2. `goto` combined with other commands. Of course, it is most combined with `if`.

The first type, character comparison: `if %a%==1 goto b`
When `%a%` is empty, an error is returned: at this time, `goto` should not be present.
Solution: Add quotes `if "%a%"=="1" goto b`

The second type, numerical comparison: `if %a% lss 1 goto b`
Because numerical comparison needs to be performed, so quotes cannot be added to avoid the situation where `%a%` is empty.
Solution 1: Handle the situation where `%a%` is empty alone before this.
Solution 2: Use delayed variables, for example `if !a! lss 1 goto b`

[ Last edited by Hanyeguxing on 2011-1-15 at 22:36 ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
xinjingdos +1 2011-01-15 22:57
Floor 3 Posted 2011-01-17 02:33 ·  中国 吉林 长春 电信
初级用户
枫中残雪
Credits 65
Posts 43
Joined 2010-04-29 23:20
16-year member
UID 165810
Gender Male
From 吉林省长春市
Status Offline
So you mean that CMD's handling of spaces is between "%variable%" and "!variable!", right? (PS: I guess it's also after %%I in FOR, otherwise how could you delete blank lines)
Forum Jump: