Reputation: 1
I'm making a batch file with need to have two inputs as follow:
echo What's the name of your two brothers
set/p input1=
set/p input2=
Now what do I want is something like this:
if %input1==anything and if %input2%==OtherThing goto Continue
But I don't know how to do it right. Please NEED HELP Thnks.
Upvotes: 0
Views: 6144
Reputation: 56
If you're trying to execute the GOTO command only if the first AND the second IF statements are true, use this:
if %input1%==anything && if %input2%==OtherThing goto continue
The &&
tells the program to execute the command after it only if the one before it is true.
You could also add some other features to the program, like ignoring the order that you enter the brothers. To do that, use this:
if %input1%==anything && if %input2%==OtherThing goto continue
if %input1%==OtherThing && if %input2%==anything goto continue
echo Your brothers do not match description etc...
pause
exit
You could also use case insensitive comparing like this:
if /I %input1%==anything && if /I %input2%==OtherThing goto continue
There are alot of other things possible to embelish your program. If you need more help with a certain command, open cmd.exe and type a command with the /? switch.
Update:
Sorry my first answer didn't work, but I have come up with the start of a new .bat program that should do the job. If this action is the first action of your program, copy and paste this code at the very beginning of your program:
@echo off
echo Enter the name of your first brother.
set /P input1=
cls
echo Enter the name of your second brother.
set /P input2=
if %input1%==anything goto %input1%
if not %input1%==OtherThing goto checkinput2
goto %input1%
:anything
if %input2%==OtherThing (goto continue) else cls & echo Only one brother matched. & echo. & pause & exit /b
:OtherThing
if %input2%==anything (goto continue) else cls & echo Only one brother matched. & echo. & pause & exit /b
:checkinput2
if %input2%==OtherThing cls & echo Only one brother matched. & echo. & pause & exit /b
if %input2%==anything cls & echo Only one brother matched. & echo. & pause & exit /b
cls
echo No brothers matched.
echo.
pause
exit /b
:continue
"the rest of your program here"
Wherever you see "anything" replace it with the name of one brother. Wherever you see "OtherThing" replace it with the name of the other brother. The names will be case senitive. Where you see "the rest of your program here", that is your :continue
statement. Just continue your program from this line.
If this action is somewhere in the middle of your program, replace the first line, @echo off
, with cls
to clear whatever was on the screen from the other program commands.
I hope this works well for you.
Upvotes: 0
Reputation: 9545
Try like this :
@echo off
echo What's the name of your two brothers
set /p "input1=Brother 1 :"
set /p "input2=Brother 2 :"
if /i "%input1%"=="anything" (
if /i "%input2%"=="OtherThing" goto Continue
echo One brother matched
pause
exit/b)
echo No Brother Matched
pause
exit/b
:continue
echo Two Brother matched
pause
Upvotes: 0
Reputation: 57252
if "%input1%" EQU "anything" if "%input2%" EQU "OtherThing" goto :Continue
Upvotes: 2