title: Bash script basic apnea timer
body: <p>I am trying to write a bash script that will prompt a user for three variables, and then display a count down type timer so I can perform <code>O2</code> tables whilst at work on my linux machine <code>(centos6)</code>, </p>
  
  <p>So far I have a really bad mix of a loop and countdown function written but i am sure that this is a very basic script for someone who comprehends bash scripting,</p>
  
  <p>Essentially I need a variable for a time interval for a breath up (breathing deeply to prepare for a period of apnea)
  A variable for the first interval of time to hold your breathe
  Then a variable to increment that hold time by a user provided value as rounds go by, </p>
  
  <p>I would prefer all the variable to be established in seconds only,</p>
  
  <p>Here's an example able of what the end result should be:</p>
  
  <p><img src="https://i.stack.imgur.com/p95Ut.png" alt="enter image description here"></p>
  
  <p>this is what i had until i got frustrated with the operation of it </p>
  
  <pre><code>#!/bin/bash
  
  echo "Welcome to the apnea timer, All values should be entered in seconds"
  sleep 0.2
  read -p "Enter Breath Up Time:" br
  read -p "Enter Starting Hold Time Interval:" hold
  read -p "Enter Hold Increment Time:" hinc
  echo "Starting..." 
  sleep 0.5
  function cw(){
     date1=$((`date +%s` + $1));   
    while [ "$date1" -ne `date +%s` ]; do   
       echo -ne "$(date -u --date @$(($date1 - `date +%s`)) +%H:%M:%S)\r";  
      sleep 0.1  
    done  
  
    if [$br -gt 0]
    do 
    cw $br 
    then 
    cw $hold
    then 
    cw $br
    then 
    cw ($hold + $hinc)
  </code></pre>