【发布时间】:2019-09-20 01:07:48
【问题描述】:
在文本文件 test.txt 中,我有以下信息:
sl-gs5 desconnected Wed Oct 10 08:00:01 EDT 2012 1001
我想通过下一个命令行提取事件的时间:
hour=$(grep -n sl-gs5 test.txt | tail -1 | cut -d' ' -f6 | awk -F ":" '{print $1}')
我得到了“08”。当我尝试加 1 时,
14 echo $((hour+1))
我收到下一条错误消息:
./test2.sh: line 14: 08: value too great for base (error token is "08")
如果 Bash 中的变量没有类型,为什么?
【问题讨论】:
-
前导 0 导致 bash 试图将您的数字解释为八进制数,但八进制数是 0-7,因此 8 是无效标记。
-
此错误来自“前导零”错误,也就是 bash 中第一个非零表示之前出现的任何 0 数字。示例(例如 01,002、0000003 等...)
标签: bash