Batch file If语句(此时意外

Batch file If语句(此时意外,batch-file,if-statement,Batch File,If Statement,找不到问题。每当我只输入1时,就会发生错误。它表示(此时意外)。但每当我输入其他数字时,只要有2位小数,就可以了 @echo off cls setlocal EnableDelayedExpansion echo|set /p= Input: set /p input= call :process endlocal goto :EOF :process if %input%==0 ( echo Input is 0 goto

找不到问题。每当我只输入1时,就会发生错误。它表示(此时意外)。但每当我输入其他数字时,只要有2位小数,就可以了

@echo off
cls
    setlocal EnableDelayedExpansion
    echo|set /p= Input: 
    set /p input=
    call :process
    endlocal
    goto :EOF

:process
if %input%==0 (
    echo Input is 0
    goto :EOF
)

if %input:~-3,1%==. (
    if %input:~0,-3%==0 (
        echo Less than 1
    ) else (
        echo Greater than 1
    )
) else (
    echo Equal to 1
)
goto :EOF
如果%input:~-3,1%=.(

表示如果[输入1个字符的
第四个字符中的字符串]==(

当输入为“1”时,[来自
input
的第四个字符的字符串对于1个字符]为空,因此这被解释为

if==。(

if
语句要求
if-string1运算符string2(dothis)

si它将
=.
视为string1,无法理解
作为运算符的含义-它期望的是有限集合中的一个;因此它抱怨说
不是期望的

治疗:


删除
@echo off
并观察输出-您将清楚地看到问题所在。我明白了。谢谢~由于参数不完整而出现错误。是。为避免此语法问题,请将等号的两边都放在双引号中:
如果“%input%”==“0”(
。这不会解决任何逻辑故障,但它可以防止批处理因语法错误而崩溃,因为如果%input%为空,则该行将转换为
if”“==“0”(
而不是
if==0(
if "%input:~-3,1%"=="." (