我的bash脚本中有以下逻辑:
#!/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以上的任何时候似乎触发错误).
关于如何解决这个问题的任何建议?
我在Ubuntu 10.04 LTS上运行
[编辑]
我修改了SiegeX建议的脚本,现在我收到错误:[:10#0910:预期的整数表达式.
任何帮助?
bash将您的数字视为八进制,因为前导零
原文链接:https://www.f2er.com/bash/386047.html从男子bash
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.
要修复它,请指定base-10前缀
#!/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