且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

值对于基数太大(错误令牌为"0925")

更新时间:2023-01-31 15:21:25

bash 将您的数字视为八进制,因为前导零

bash is treating your numbers as octal because of the leading zero

常数为0的常数是解释为八进制数.一种前导0x或0X表示十六进制.否则,数字采用[base#] n的形式,其中base是小数2到64之间的数字表示-算术基数,并且n是该基数中的数字.如果base#是省略,则使用10为底.

Constants with a leading 0 are interpreted as octal numbers. A leading 0x or 0X denotes hexadecimal. Otherwise, numbers take the form [base#]n, where base is a decimal number between 2 and 64 represent- ing the arithmetic base, and n is a number in that base. If base# is omitted, then base 10 is used.

要解决此问题,请指定以10为底的前缀

To fix it, specify the base-10 prefix

#!/bin/bash
local_time="10#$(date +%H%M)"

if (( ( local_time > 1430  && local_time < 2230 ) || ( local_time > 0300 && local_time < 0430 ) )); then
 # do something
fi