如何在特定时间之前执行bash脚本循环 [英] How to have a bash script loop until a specific time
本文介绍了如何在特定时间之前执行bash脚本循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
通常要运行一个无限的bash循环,我会执行以下操作:
Usually to run an infinite bash loop, I do something like the following:
while true; do
echo test
sleep 1
done
如果相反,我想做一个无限循环的循环,只要它早于20:00.有什么办法可以在bash中做到这一点?
What if instead, I want to do a loop that loops infinitely as long as it is earlier than 20:00. Is there a way to do this in bash?
推荐答案
您可以使用date
打印小时,然后与您要查找的小时进行比较:
You can use date
to print the hours and then compare to the one you are looking for:
while [ $(date "+%H") -lt 20 ]; do
echo "test"
sleep 1
done
date "+%H"
显示当前时间,它会一直检查我们是否已经到场或在较小"的时间里.
as date "+%H"
shows the current hour, it keeps checking if we are already there or in a "smaller" hour.
这篇关于如何在特定时间之前执行bash脚本循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文