Windows Shell脚本“这时是意外的."在命令提示符下 [英] Windows Shell Script "is was unexpected at this time." in Command Prompt

查看:91
本文介绍了Windows Shell脚本“这时是意外的."在命令提示符下的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这很新,如果这很简单,我深表歉意.我正在命令提示符下运行以下.bat脚本进行分配.

Very new to this, so I apologize if this is something simple. I am running the following .bat script in Command Prompt for an assignment.

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

脚本将提示敲敲!"尽管应该,但是在回答谁在那儿?" (不带引号),出现错误此时是意外".我在做什么错了?

The script will prompt "Knock Knock!" as it should, but upon responding "Who is there?" (w/o quotations), I am presented with the error "is was unexpected at this time". What am I doing wrong?

再次,我意识到这可能是非常基础的,因此,我感谢任何帮助.

Again, I realize this is probably very elementary, so I appreciate any help.

谢谢.

推荐答案

问题是,当%reply%变量替换为其值时,cmd试图解释这一点:

The problem is that when the %reply% variable is substituted with its value, cmd tries to interpret this:

IF NOT Who is there? == "Who is there?" (

而不是:

IF NOT "Who is there?" == "Who is there?" (

要解决此问题,请在%reply%周围添加引号,如下所示:

To fix it, add quotes around %reply%, like this:

IF NOT "%reply%" == "Who is there?" (
  ECHO "Sorry, but you are not playing the game right!"
  GOTO :EOF)

这篇关于Windows Shell脚本“这时是意外的."在命令提示符下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆