我有一个批处理脚本(以“战争游戏”中的约书亚为模型)
@echo off
color 0b
echo Greetings, Professor Falken
set /p interface =
echo Would You Like to Play a Game?
set /p ifGame =
if /i "%ifGame%" =="yes" goto yesgame
if /i "%ifGame%" =="no" goto nogame
:yesgame
echo List of Games
echo chess
echo Poker
echo Fighter Combat
echo Guerilla Warfare
echo Desert Warfare
echo Air-to-Ground Actions
echo Theaterwide Tactical Warfare
echo Theaterwide Biotoxic and Chemical Warfare
echo Global Thermonuclear War
pause
echo Which game would you like to play?
set /p WhichGame =
pause
exit
:nogame
set /p areYouSure=Are You Sure?
pause
exit
但是,当我输入“No”时,它仍会显示游戏列表......
答案 0 :(得分:3)
使用=
时,您需要删除变量名称和set /p
符号之间的空格。从:
set /p ifGame =
要:
set /p ifGame=
否则,您设置的变量在名称末尾有一个空格。因此%ifGame%
扩展为空,而%ifGame %
将扩展为正确的值。