bash - 值对于 base 来说太大了(错误标记是 "09")

标签 bash

当运行我的 bash 脚本的这一部分时出现错误

脚本

value=0
for (( t=0; t <= 4; t++ ))
do
d1=${filedates[$t]}
d2=${filedates[$t+1]}
((diff_sec=d2-d1))
SEC=$diff_sec
compare=$((${SEC}/(60*60*24)))
value=$((value+compare))
done

输出

jad.sh: line 28: ((: 10#2014-01-09: value too great for base (error token is "09")
jad.sh: line 30: /(60*60*24): syntax error: operand expected (error token is "/(60*60*24)")

d1 和 d2 是 2014-01-09 和 2014-01-10 形式的日期

有什么解决办法吗?

最佳答案

将字符串“10#”添加到变量的前面。这迫使 bash 将它们视为十进制,即使前导零通常会使它们成为八进制。

关于bash - 值对于 base 来说太大了(错误标记是 "09"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21049822/

相关文章:

bash - 从 grep 中获取空白字符到数组中

bash - 使用不同的输入文件运行脚本

linux - k 参数在排序函数中有什么作用(Linux Bash 脚本)?

linux - Bash 创建变量然后为其赋值

bash - AWK 将 NULL 列值替换为前一行的列值(续)

linux - 使用 tr 命令将单个单词变为大写

mysql - 在 bash shell 脚本中解析 MySQL Community Edition 5.7 自动生成的临时 root 密码

windows - 如何从 Windows 任务计划程序在 ( ubuntu bash windows 10 ) 上运行程序

bash - 在 -exec 中运行命令之前对 find 的输出进行排序

bash - 测试环境变量列表是否都设置为某些值