值对于基数太大(错误令牌为"0925") [英] Value too great for base (error token is "0925")
问题描述
我的bash脚本中具有以下逻辑:
I have the following logic in my bash script:
#!/bin/bash
local_time=$(date +%H%M)
if (( ( local_time > 1430 && local_time < 2230 ) || ( local_time > 0300 && local_time < 0430 ) )); then
# do something
fi
我时不时地得到标题中指定的错误(在 08xx
上方的任何时间似乎都会触发该错误).
Every now and then, I get the error specified in the title (any time above 08xx
appears to trigger the error).
关于如何解决此问题的任何建议?
Any suggestions on how to fix this?
我正在Ubuntu 10.04 LTS上运行
I am running on Ubuntu 10.04 LTS
我按照SiegeX的建议修改了脚本,现在,我得到了错误: [:10#0910:预期为整数表达式
.
I modified the script as suggested by SiegeX, and now, I am getting the error: [: 10#0910: integer expression expected
.
有帮助吗?
推荐答案
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
这篇关于值对于基数太大(错误令牌为"0925")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!