简体   繁体   English

此时,后藤出乎意料[BATCH]

[英]Goto was unexpected at this time [BATCH]

So basically I was working on my Terminal I am creating in batch and this strange error pops up for a second and then the window closes: "Goto was unexpected at this time" I have no idea what's going on. 因此,基本上,我正在批量创建终端时工作,该奇怪的错误弹出一秒钟,然后窗口关闭:“此时Goto出乎意料”,我不知道发生了什么。 Here's my code: 这是我的代码:

 @ECHO off
 set codename=Nature
 echo Windows Bat Terminal
 echo Codename "%codename%"
 :terminal
 set /p terminalcommand=Command: 
 if %terminalcommand%==help goto help
 if %terminalcommand%==clr goto clear
 if %terminalcommand%==exit goto exit
 if %terminalcommand%==color goto color
 if %terminalcommand%==time goto timedate
 echo.
 echo Bad command!
 :terminal1
 goto terminal`

To recreate simply run this in CMD. 要重新创建,只需在CMD中运行即可。

You haven't told us what entry you made to generate this behaviour. 您尚未告诉我们您输入了什么来生成此行为。 The standard cure is to quote each side if the if comparison (if /i "%terminalcommand%"=="time" goto ... (the /i make the comparison case-insensitive)) because if you simply press enter then the command is resolved to "if ==time goto ..." and cmd will see goto where it expects a comparison operator like ==, hence the response. 标准的解决方法是用if进行比较(如果/ i“%terminalcommand%” ==“ time” goto ...(/ i使比较不区分大小写),则在每一面都加引号,因为如果您只是按Enter,则命令被解析为“如果== time goto ...”,则cmd将在goto处看到期望==这样的比较运算符的位置,因此响应。 If you run this batch from the command prompt, the window won't close and you'll be able to see these messages better 如果您在命令提示符下运行此批处理,则该窗口不会关闭,您将能够更好地查看这些消息

 goto terminal` 

Remove the ` at the end. 最后删除`。 I guess it was accidentally placed there. 我猜是不小心把它放在那里了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM