作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
根据我的代码,如果%~1
大于7000
,则转到ExceedError
IF "%~1" GTR "7000" GOTO ExceedError
ExceedError
的内容:
ECHO Value exceeded the maximum value. See help file.
EXIT /B
但是这发生了:
...modules>If "71" GTR "7000" GOTO ExceedError
...modules>Echo Value exceeded the maximum value. See help file.
Value exceeded the maximum value. See help file.
...modules>exit /B
发生了什么事?有什么问题吗?
最佳答案
您用双引号将参数括起来,这会强制进行字符串比较。要比较数字,请尝试不使用引号:
IF %~1 GTR 7000 GOTO ExceedError
如果您想防止错误,您可以再添加一行:
set /a "_number=%~1" >nul 2>&1 || set "_number=0"
IF %_number% GTR 7000 GOTO ExceedError
如果输入错误,您会将这些值与作为默认值的 0
进行比较。如果需要,您可以更改它
关于batch-file - IF "71"GTR "7000"产生 true,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53059990/
我是一名优秀的程序员,十分优秀!