1

This is the script:

@echo off

set BSL_Scripter_go="BSL_Scripter.exe"
set BSL_Script=WriteMain_s.txt
set yes=Y
set no=N


::%BSL_Scripter_go% %BSL_Script%

:LABEL1
set /p answer=Have you turned device off?[Y\N]

IF "%answer%"=="%yes%" (GOTO LABEL_DEVICE_RUN
) ELSE (IF "%answer%"=="%no%"(GOTO LABEL1) ELSE (GOTO LABEL_TYPO))

:LABEL_DEVICE_RUN
echo Device is runing..
GOTO END

:LABEL_TYPO
echo UNCORRECT ANSWER, PLEASE TYPE 'Y' or 'N'
GOTO LABEL1

:END

and I got the error:

ELSE was unexpected at this time

Little help?

phuclv
  • 37,963
  • 15
  • 156
  • 475
Radoslaw Krasimirow
  • 1,833
  • 2
  • 18
  • 28

2 Answers2

2

There is a SPACE missing between "%no%" and (GOTO LABEL1):

IF "%answer%"=="%no%" (GOTO LABEL1)

Otherwise, "%no%"(GOTO is the string to compare and so there a closing ) too much. The command line interpreter tries to execute the following line (omitting values and commands for visualisation):

IF <value>==<value> (command) ELSE (IF value==value command) ELSE (command))

You will notice that it looks like there are two ELSE clauses for the first IF statement.

Side Note: I recommend using /IF /I "%answer%"==... so that Y/N and y/n are accepted.

aschipfl
  • 33,626
  • 12
  • 54
  • 99
1

This drove me nuts. In my case it was unescaped() in my comment lines prefixed with :: inside my IF statements.

Apparently one should be using REM inside IF statements instead of ::, but escaping all my ^(m ^) (even in non-comment lines, i.e. ECHO statements) worked for me.

See: https://stackoverflow.com/a/16839602/913223

Daniel Sokolowski
  • 11,982
  • 4
  • 69
  • 55