Dimitar Bogdanov
Dimitar Bogdanov

Reputation: 11

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. 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.

Upvotes: 0

Views: 1098

Answers (1)

Magoo
Magoo

Reputation: 80211

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 you run this batch from the command prompt, the window won't close and you'll be able to see these messages better

Upvotes: 2

Related Questions