开发者

check if timestamp is in certain range using bash script

Say I have a bunch of time stamps

As I iterate over these timestamps,

01:23:00
12开发者_开发问答:34:14
17:09:12
...

I want to include only timestamps between 08:00:00 and 17:00:00

please suggest


You can do a simple string comparison:

if [[ "$timestamp" > "08:00:00" && "$timestamp" < "17:00:00" ]]

If you want to include the ends of your range, you'll have to test for that separately since Bash doesn't have a >= or <= operators for strings:

start="08:00:00"
end="17:00:00"
if [[ "$timestamp" == "$start" ||
      "$timestamp" >  "$start" && "$timestamp" <  "$end" ||
                                  "$timestamp" == "$end" ]]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜