庆典:值太大,基地(错误标记是" 0925") [英] bash: 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
然后每一个现在,我得到的称号指定的错误(上述山东省实验中学的任何时间出现触发错误)。
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:整数EX pression有望
I modified the script as suggested by SiegeX, and now, I am getting the error: [: 10#0910: integer expression expected
任何帮助吗?
推荐答案
庆典
正在处理您的数字作为八由于前导零
bash
is treating your numbers as octal because of the leading zero
与一家领先的0是常数
除preTED为八进制数字。一个
0x或0X表示十六进制。
否则,数字的形式是[基#] n,其中基地是一个小数
2和64重新present-之间数
ING运算的基础上,和n是在该基的一个数字。如果基地是#
省略,则使用基底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 preFIX
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
这篇关于庆典:值太大,基地(错误标记是&QUOT; 0925&QUOT;)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!