当我减去两个变量的值时,我总是返回0,尽管变量值的差异不是这样。
我正在尝试编写一个脚本,它将给我自上次更新文件以来经过的时间。我有一个变量'CurTime',它是自纪元以来的当前时间(以秒为单位),以及第二个变量'FileUpdated',它是自纪元以来以秒为单位的文件时间戳。
File="test.txt"
FileUpdated= date -r $File "+%s"
CurTime= date +%s
TimeDiff=$(( CurTime - FileUpdated ))
echo $TimeDiff
我上次运行脚本时,它将CurTime的值打印为1559259780,将FileUpdated的时间打印为1559252608,因此我希望返回值7172,但收到的输出为0。
发布于 2019-05-31 09:39:20
问题在于如何定义变量。我做了更改,以下脚本有效:
File="test.txt"
echo $File
FileUpdated=$(date -r $File "+%s")
echo $FileUpdated
CurTime=$(date +%s)
echo $CurTime
TimeDiff=$((CurTime-FileUpdated))
echo $TimeDiff
https://stackoverflow.com/questions/-100006875
复制相似问题