gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 20:22:23 29 4
gpt4 key购买 nike

我有一个越来越大的批处理文件,它使用 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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com