Advertisement
metalx1000

Basic BASH Timer

Sep 7th, 2018
1,904
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.29 KB | None | 0 0
  1. #!/bin/bash
  2. ######################################################################
  3. #Copyright (C) 2018  Kris Occhipinti
  4. #https://filmsbykris.com
  5.  
  6. #This program is free software: you can redistribute it and/or modify
  7. #it under the terms of the GNU General Public License as published by
  8. #the Free Software Foundation, either version 3 of the License, or
  9. #(at your option) any later version.
  10.  
  11. #This program is distributed in the hope that it will be useful,
  12. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. #GNU General Public License for more details.
  15.  
  16. #You should have received a copy of the GNU General Public License
  17. #along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18. ######################################################################
  19.  
  20. let start_time="$(date +%s)";
  21.  
  22. function main(){
  23.   echo "Welcome to my timer"
  24.   start_timer
  25.   exit 0
  26. }
  27.  
  28. function start_timer(){
  29.   while [ 1 ];
  30.   do
  31.     let current_time="$(date +%s)"
  32.     let seconds=$current_time-$start_time;
  33.  
  34.     echo -en "\r                                        \r"
  35.     printf "Timer: %02d:%02d:%02d:%02d" "$((seconds/86400))" "$((seconds/3600%24))" "$((seconds/60%60))" "$((seconds%60))"
  36.     sleep 1;
  37.   done
  38. }
  39.  
  40. main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement