Muy nuevo en esto, así que me disculpo si esto es algo simple. Estoy ejecutando el siguiente script .bat en el símbolo del sistema para una tarea.
@ECHO off
TITLE "KnockKnock.bat - The KnockKnock joke game!"
COLOR 0E
CLS
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
SET /p reply="Knock Knock! C:>"
CLS
IF NOT %reply% == "Who is there?" (
ECHO "Sorry, but you are not playing the game right!"
GOTO :EOF)
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
SET /p reply="Orange! C:>"
CLS
IF NOT %reply% == "Orange who?" (
ECHO "Sorry, but you are not playing the game right!"
GOTO :EOF)
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO "Orange you glad you"ve written your first Windows shell script?"
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
ECHO.
El guión mostrará "Knock Knock!" como debería, pero al responder "¿Quién está allí?" (sin citas), me aparece el error "fue inesperado en este momento". ¿Qué estoy haciendo mal?
Nuevamente, me doy cuenta de que esto es probablemente muy elemental, así que agradezco cualquier ayuda.
Gracias.
Respuestas
2 para la respuesta № 1El problema es que cuando el %reply%
la variable se sustituye por su valor, cmd intenta interpretar esto:
IF NOT Who is there? == "Who is there?" (
En vez de esto:
IF NOT "Who is there?" == "Who is there?" (
Para solucionarlo, agregue citas alrededor %reply%
, Me gusta esto:
IF NOT "%reply%" == "Who is there?" (
ECHO "Sorry, but you are not playing the game right!"
GOTO :EOF)