[英]Bash script to calculate time difference
I would appreciate any kind of help.I am a beginner in the bash script. 我将不胜感激。我是bash脚本的初学者。
I am trying to subtract several times from the time of the start to get a list of time in seconds. 我试图从开始的时间中减去几次,以获得以秒为单位的时间列表。 See my input file how I did.
看看我的输入文件是怎么做的。 It didn't work, if anyone can help on that, I would appreciate it.
它没有用,如果有人可以提供帮助,我将不胜感激。
#!/bin/bash
# start time
TIME=10:46:20
# recorded time
TIME_Record=(
11:03:00
11:24:00
11:27:00
11:32:00
)
SEC1=`date +%s -d ${TIME}`
SEC2=`date +%s -d ${TIME_Record}`
DIFFSEC=`expr ${SEC2} - ${SEC1}`
I guess you are just having difficulties to formulate the loop in bash syntax. 我想您只是很难用bash语法来表达循环。 Here you go:
干得好:
#!/bin/bash
START_TIME=10:46:20
TIME_Record=(
11:03:00
11:24:00
11:27:00
11:32:00
)
SEC1=$(date +%s -d "${START_TIME}")
for d in "${TIME_Record[@]}"
do
SEC2=$(date +%s -d "$d")
DIFFSEC=$(( SEC2 - SEC1 ))
echo "$DIFFSEC"
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.