I'm simply working on a password for my batch file;but, my if statement is not working. when I ask it to check whether my password is correct, it goes to the else statement, even if i correctly enter the password (hi). here is the part of my code that has the problem:
if "%R%"=="hi" (
goto b
) else (
echo access denied.
goto f
)
and here is the entire code:
echo off
color 0f
pause
:f
set /p R = "Please enter your passcode "
if "%R%"=="hi" (
goto b
) else (
echo access denied.
goto f
)
:a
for /L %%A IN (1,1,234) DO (
color 6e
echo %random%%random%%random%%random%%random%%random%%random%
color 2a
echo %random%%random%%random%%random%%random%%random%%random%%random%
color 1b
echo %random%%random%%random%%random%%random%%random%%random%%random%
color 5d
echo %random%%random%%random%%random%%random%%random%%random%%random%
color 4c
echo %random%%random%%random%%random%%random%%random%%random%%random%
)
GOTO c
:b
echo Welcome Back
pause >nul
echo Your current computer does not contain previous files.
pause >nul
echo Download Backup Files now?
pause >nul
echo Downloading all Files...
goto a
:c
echo access granted. welcome to the CIA Mainframe.
pause >nul
echo Please se-se-select a c-command.
pause >nul
echo Alert! Alert! The main Fire wall has been Breached!
pause >nul
echo Files being deleted now...
pause >nul
:d
color 0c
echo %random%%random%%random%%random%%random%%random%%random%
echo %random%%random%%random%%random%%random%%random%%random%%random%
echo %random%%random%%random%%random%%random%%random%%random%%random%
echo %random%%random%%random%%random%%random%%random%%random%%random%
echo %random%%random%%random%%random%%random%%random%%random%%random%
goto d
Can anyone please help.
答案 0 :(得分:1)
这是变量中空格的问题。
从命令行尝试:
>set /p R = "Please enter your passcode: "
Please enter your passcode: blah
>echo %R%
%R%
>echo %R %
blah
将您的行更改为:
set /p "R=Please enter your passcode: "
这应该解决。