Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Batch file &引用;命令的语法(算术表达式)不正确;在嵌套的“中”;如果;批处理语句_Batch File_If Statement_Arithmetic Expressions - Fatal编程技术网

Batch file &引用;命令的语法(算术表达式)不正确;在嵌套的“中”;如果;批处理语句

Batch file &引用;命令的语法(算术表达式)不正确;在嵌套的“中”;如果;批处理语句,batch-file,if-statement,arithmetic-expressions,Batch File,If Statement,Arithmetic Expressions,我正在编写一个批处理文件,遇到了一个问题。我需要在批处理脚本中生成“OR”语句和“OR”语句。 这是我的密码: @echo off set /p a="a=" set /p b="b=" if "%a%" == "5" ( if "%b%" == "8" ( set /a "c=%a%*%b%" goto :win ) if "%b%" == "2"( set /a "c=%a%+%b%" goto :wi

我正在编写一个批处理文件,遇到了一个问题。我需要在批处理脚本中生成“OR”语句和“OR”语句。 这是我的密码:

@echo off
set /p a="a="
set /p b="b="
if "%a%" == "5" (
    if "%b%" == "8" (
        set /a "c=%a%*%b%"
        goto :win 
    )
    if "%b%" == "2"(
        set /a "c=%a%+%b%"
        goto :win 
    )   
)
goto :fail
:win
echo %c%
goto :exit
:fail
echo U'r not a magician!
:exit
pause

问题是,如果没有第二个嵌套的“IF”表达式,它只能正常工作,但我需要同时获得这两个结果的可能性。

“2”
之间插入
空格时,代码可以正常工作

导致问题的线路是:

if "%b%" == "2"(
若要修复,请将代码更改为:

if "%b%" == "2" (

当您在
“2”
之间插入
空格时,您的代码工作得非常好

导致问题的线路是:

if "%b%" == "2"(
若要修复,请将代码更改为:

if "%b%" == "2" (

既然您已经接受了您的答案,我只想指出您的代码似乎是OTT,因为您已经知道接受的参数以及您将如何处理它们。(实际上不需要执行算术运算)。此结构将以相同的方式运行:

@Echo关闭
设置/P“a=a=”
设置/P“b=b=”
设置“c=”
如果“%a%][%b%=”5][8“设置为”c=40”
如果“%a%][%b%=”5][2“设置”c=7”
如果定义了c(Echo=%c%),则为其他(Echo=U'r不是魔术师!)
暂停

既然您已经接受了答案,我只想提一下您的代码似乎是OTT,因为您已经知道接受的参数以及您将如何处理它们。(实际上不需要执行算术运算)。此结构将以相同的方式工作:

@Echo关闭
设置/P“a=a=”
设置/P“b=b=”
设置“c=”
如果“%a%][%b%=”5][8“设置为”c=40”
如果“%a%][%b%=”5][2“设置”c=7”
如果定义了c(Echo=%c%),则为其他(Echo=U'r不是魔术师!)
暂停