救救我!
@ECHO off
echo ------------------
echo 1. Shutdown(S)
echo 2. File(F)
echo 3. Compile Program(C)
echo ------------------
set /p answer = Choose:
echo %answer%
if %answer% == "S" (
call shutdown.bat
) else (
echo unok
)
結果
------------------
1. Shutdown(S)
2. File(F)
3. Compile Program(C)
------------------
Choose:S
0
unok
請問為什麼是讀到0
?
二個地方要修改
@ECHO off
echo ------------------
echo 1. Shutdown(S)
echo 2. File(F)
echo 3. Compile Program(C)
echo ------------------
::set /p answer = Choose: 變數後面沒有空格
set /p answer= Choose:
echo %answer%
::if %answer% == "S" ( 比對文字應該用以雙引號組成一組
if "%answer%" == "S" (
call shutdown.bat
) else (
echo unok
)
一舨如果項選不多及只有單字,可以使用choice 好處是可限制只能輸入指定的符號,輸入錯誤還能發出提示音,後面依條件直接Goto 到指定的位置,不需再用IF來判斷
CHOICE /C YNC /M "按是(Y)、否(N)或取消(C)。"
Goto :%Errorlevel%
:1
Echo 1........
Pause
Goto :EOF
:2
Echo 2........
Pause
Goto :EOF
:3
Echo 3........
Pause
Goto :EOF