首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >当满足"IF Not%Reply%==“条件时,Windows Shell脚本没有回显

当满足"IF Not%Reply%==“条件时,Windows Shell脚本没有回显
EN

Stack Overflow用户
提问于 2018-06-04 02:44:28
回答 1查看 76关注 0票数 0

我正在使用与Windows Shell Script “is was unexpected at this time.” in Command Prompt相同的Shell脚本。这里的解决方案对Jerry (请求者)有效,也帮助了我,直到我测试了IF NOT条件。下面是有问题的代码:

代码语言:javascript
复制
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)

在Jerry的例子中,蓝胡子提供了一个解决方案,%reply%应该用引号括起来,这样它就可以测试:

代码语言:javascript
复制
IF NOT "Who is there?" == "Who is there?"

而不是:

代码语言:javascript
复制
IF NOT Who is there? == "Who is there?"

这导致了Jerry和我都得到了错误:is was unexpected at this time

在使用蓝胡子的解决方案后,错误消失了,但是当我尝试输入Who is there?而不是"Who is there?"来检查验证时,代码跳过了验证ECHO "Sorry, but you are not playing the game right!"

我遗漏了什么?有什么建议吗?

EN

回答 1

Stack Overflow用户

发布于 2018-06-04 05:37:44

根据Compo的提示,只检查回复是否包含单词whothere case独立:

代码语言:javascript
复制
SET /p reply="Knock knock!  C:>"
CLS
If not defined reply goto :wrong
echo %reply%|find /i "who" 2>&1>Nul && echo %reply%|find /i "there" 2>&1>Nul && Echo goto :right
:wrong
ECHO "Sorry, but you are not playing the game right!"
GOTO :EOF
:right
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50669781

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档