小编Sin*_*abi的帖子

如何检查当前时间是否在 23:00 和 06:30 之间

如果当前时间在 23:00 和 06:30 之间,我无法掌握如何从 bash 脚本中正确检查。我正在尝试运行一个无限循环来检查现在的时间,并在时间范围在晚上 11 点到早上 6 点 30 之间时做一些事情。这是我到目前为止所写的内容,第二天不起作用:

fireup()
{

 local starttime=$(date --date="23:00" +"%s")
 local endtime=$(date --date="06:30" +"%s")

 while :; do
     local currenttime=$(date +%s)
     if [ "$currenttime" -ge "$starttime" -a "$currenttime" -ge "$endtime" ]; then
        do_something
     else
         do_something_else
     fi
     test "$?" -gt 128 && break
     local currenttime=$(date +%s)
 done &
 }
Run Code Online (Sandbox Code Playgroud)

我做错了什么?

scripting date

18
推荐指数
3
解决办法
5万
查看次数

标签 统计

date ×1

scripting ×1