• shell倒计时下班时间


    #!/bin/sh
    
    offWorkTime="19:00:00"
    offWorkHour=${offWorkTime:0:2}
    offWorkMinute=${offWorkTime:3:2}
    offWorkSecond=${offWorkTime:6:2}
    
    currentTime=`TZ='Asia/Hong_Kong' date +%H:%M:%S`
    currentHour=${currentTime:0:2}
    currentMinute=${currentTime:3:2}
    currentSecond=${currentTime:6:2}

    second=$((offWorkSecond - currentSecond))
    if [[ $second -lt 0 ]]
    then
      second=$((second + 60))
      offWorkMinute=$((offWorkMinute - 1))
      if [[ $offWorkMinute -lt 0 ]]
      then
        offWorkMinute=$((offWorkMinute + 60))
        offWorkHour=$((offWorkHour - 1))
      fi
    fi

    minute=$((offWorkMinute - currentMinute))
    if [[ $minute -lt 0 ]]
    then
      minute=$((minute + 60))
      offWorkHour=$((offWorkHour - 1))
    fi

    hour=$((offWorkHour - currentHour))

    while true
    do
      second=$((second - 1))
      if [[ $second -lt 0 ]]
      then
        second=$((second + 60))
        minute=$((minute - 1))
        if [[ $minute -lt 0 ]]
        then
          minute=$((minute + 60))
          hour=$((hour - 1))
        fi
      fi

      if [[ $second -lt 10 ]]
      then
        secondStr="0$second"
      else
        secondStr="$second"
      fi

      if [[ $minute -lt 10 ]]
      then
        minuteStr="0$minute"
      else
        minuteStr="$minute"
      fi

      if [[ $hour -lt 10 ]]
      then
        hourStr="0$hour"
      else
        hourStr="$hour"
      fi

      tput cup 0 0
      tput civis
      echo $(tput setaf 1; tput setab 6; tput bold)"offworkTime: $hourStr:$minuteStr:$secondStr"$(tput sgr0)

      if [[ $hour -eq 0 && $minute -eq 0 && $second -eq 0 ]]
      then
        break
      fi

      sleep 1s
    done
  • 相关阅读:
    Maven下载依赖项的源代码(source code)和Javadoc
    Spring读写xml文件
    重建二叉树
    从尾到头打印链表
    替换空格
    洞穴逃生
    二维数组中的查找
    分苹果
    最小生成树算法prim and kruskal
    HTTP报文格式详解
  • 原文地址:https://www.cnblogs.com/sssblog/p/10186398.html
Copyright © 2020-2023  润新知