If the instruction does not work (goes directly to another)

I am just working on a password for my batch file, but my if statement does not work. when I ask to check if my password is correct, it goes to the else statement, even if I enter the password correctly (hello). 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 whole 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 

Someone can help.

+5
source share
1 answer

This is a problem with spaces in your variable.

Try this from the command line:

 >set /p R = "Please enter your passcode: " Please enter your passcode: blah >echo %R% %R% >echo %R % blah 

Change your line to:

 set /p "R=Please enter your passcode: " 

And that should fix it.

+1
source

Source: https://habr.com/ru/post/1247666/


All Articles