batch-file - 如果批量使用GTR/LSS运算符

标签 batch-file

我有一个越来越大的批处理文件,它使用 GTR/LSS 运算符。问题是 if 语句只允许我输入某些值。在以下示例中,输入值 2、3 或 4 将返回“值太高”。

:char_intb
set char_points=30
set /a limit=!char_points!-3
set /p char_int="How many points for intelligence? "
if "!char_int!" GTR "!limit!" echo Value too high. && goto char_intb
if "!char_int!" GTR "!char_points!" echo Insufficient points. && goto char_intb
if "!char_int!" LSS "1" echo Select a value greater than or equal to 1. && goto char_intb
set /a char_points=!char_points!-!char_int!
echo You now have !char_points! remaining.

还有其他的。据我测试,它似乎只允许我输入 0 或 11。

set /p char_month="Month (0-11): "
if "!char_month!" GTR "11" echo Enter a value between 0 and 11. && echo. && goto last_char

我哪里出错了?

最佳答案

不要使用双引号 "!char_month!"GTR "11" 用于数字比较,在这种情况下,cmd 将执行字符串比较。这应该有效:

@ECHO OFF &SETLOCAL
:last_char
set /p "char_month=Month (0-11): "
if %char_month% GTR 11 (
    echo Enter a value between 0 and 11.
    echo.
    goto last_char
)
ECHO %char_month%

关于batch-file - 如果批量使用GTR/LSS运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17680639/

相关文章:

windows - 如何在 Windows 批处理文件中生成 "are you sure"提示符?

javascript - 如何在客户端运行程序或批处理文件?

batch-file - 交互式批处理文件

自动执行备份bat时mysqldump错误1728

sql - 如何使用管道|作为批处理脚本中 SQL 查询的一部分

windows - IF 中的转义字符

windows - 如何将 Windows "where"命令的输出存储在批处理文件中的变量中?

windows - 批处理文件中的 "EXIT"无法覆盖以前命令的返回码

loops - 批处理脚本中的 for 循环增加两个或多个变量

r - 从 Windows 终端安装 R & RTools