Batch file 批处理文件的一行中有两个If语句

Batch file 批处理文件的一行中有两个If语句,batch-file,if-statement,Batch File,If Statement,我正在制作一个批处理文件,需要有两个输入,如下所示: echo What's the name of your two brothers set/p input1= set/p input2= 现在我想要的是这样的东西: if %input1==anything and if %input2%==OtherThing goto Continue if /I %input1%==anything && if /I %input2%==OtherThing goto contin

我正在制作一个批处理文件,需要有两个输入,如下所示:

echo What's the name of your two brothers
set/p input1=
set/p input2=
现在我想要的是这样的东西:

if %input1==anything and if %input2%==OtherThing goto Continue
if /I %input1%==anything && if /I %input2%==OtherThing goto continue
但我不知道怎么做才对。需要帮助吗 Thnks.

试着这样做:

@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
试着这样做:

@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

如果仅当第一个和第二个If语句为true时才尝试执行GOTO命令,请使用以下命令:

if %input1%==anything && if %input2%==OtherThing goto continue
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
&&
告诉程序,只有在前一个命令为真时,才在后一个命令执行

您还可以向程序中添加一些其他功能,例如忽略您输入兄弟的顺序。为此,请使用以下命令:

if %input1%==anything && if %input2%==OtherThing goto continue
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
您也可以像这样使用不区分大小写的比较:

if %input1==anything and if %input2%==OtherThing goto Continue
if /I %input1%==anything && if /I %input2%==OtherThing goto continue
还有很多其他的东西可以用来修饰你的程序。如果您需要有关某个命令的更多帮助,请打开cmd.exe并键入带/?开关

更新:

很抱歉,我的第一个答案不起作用,但我已经提出了一个新的.bat程序的开始,应该可以完成这项工作。如果此操作是程序的第一个操作,请在程序的最开始处复制并粘贴此代码:

@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"
无论你在哪里看到“任何东西”,都要用一个兄弟的名字来代替它。无论你在哪里看到“OtherThing”,都要用另一个兄弟的名字来代替它。名称将区分大小写。在这里您可以看到“程序的其余部分”,这是您的
:continue
语句。从这一行继续你的程序

如果这个动作在你的程序中间,替换第一行,<代码> @回音> <代码>,用<代码> CLS >从其他程序命令中清除屏幕上的任何内容。


我希望这对您很有用。

如果您仅在第一个和第二个If语句为true时才尝试执行GOTO命令,请使用以下命令:

if %input1%==anything && if %input2%==OtherThing goto continue
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
&&
告诉程序,只有在前一个命令为真时,才在后一个命令执行

您还可以向程序中添加一些其他功能,例如忽略您输入兄弟的顺序。为此,请使用以下命令:

if %input1%==anything && if %input2%==OtherThing goto continue
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
您也可以像这样使用不区分大小写的比较:

if %input1==anything and if %input2%==OtherThing goto Continue
if /I %input1%==anything && if /I %input2%==OtherThing goto continue
还有很多其他的东西可以用来修饰你的程序。如果您需要有关某个命令的更多帮助,请打开cmd.exe并键入带/?开关

更新:

很抱歉,我的第一个答案不起作用,但我已经提出了一个新的.bat程序的开始,应该可以完成这项工作。如果此操作是程序的第一个操作,请在程序的最开始处复制并粘贴此代码:

@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"
无论你在哪里看到“任何东西”,都要用一个兄弟的名字来代替它。无论你在哪里看到“OtherThing”,都要用另一个兄弟的名字来代替它。名称将区分大小写。在这里您可以看到“程序的其余部分”,这是您的
:continue
语句。从这一行继续你的程序

如果这个动作在你的程序中间,替换第一行,<代码> @回音> <代码>,用<代码> CLS >从其他程序命令中清除屏幕上的任何内容。


我希望这对您很有用。

滴水和的副本。如果“a”==“a”如果“b”==“b”命令,则删除和的副本。如果“a”==“a”如果“b”==“b”命令对不起,那不行<代码>&此时发生意外。(它需要一个命令;
&&
不是命令)我应该在安装之前测试一下这段代码。它在我的电脑上也不起作用。我将添加另一个答案,希望能达到这个目的。我已经用一些伪代码进行了更新,应该对您有用。对不起,这不起作用<代码>&此时发生意外。(它需要一个命令;
&&
不是命令)我应该在安装之前测试一下这段代码。它在我的电脑上也不起作用。我将添加另一个答案,希望能达到这个目的。我已经用一些伪代码进行了更新,应该对您有用。