我正在使用与Windows Shell Script “is was unexpected at this time.” in Command Prompt相同的Shell脚本。这里的解决方案对Jerry (请求者)有效,也帮助了我,直到我测试了IF NOT
条件。下面是有问题的代码:
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%
应该用引号括起来,这样它就可以测试:
IF NOT "Who is there?" == "Who is there?"
而不是:
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!"
我遗漏了什么?有什么建议吗?
发布于 2018-06-04 05:37:44
根据Compo的提示,只检查回复是否包含单词who
和there
case独立:
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
https://stackoverflow.com/questions/50669781
复制相似问题