title: Unix current time subtraction with fixed time
body: <p>Requirement is to run the script after 4AM, the script is invoked at random time, so at the beginning of the script the below snippet is added:</p>
  
  <pre><code>while [ $(date +"%H%M%S") -lt 040000 ]
  do
      curTime=$(date -u +"%H%M%S")
      reqTime=040000
      subTime=$(expr $reqTime - $curTime)
      if [ $cntTime -ge 0 ]
      then    
          sleep $cntTime
      fi
  done
  </code></pre>
  
  <p>It checks if <code>curTime &lt; 4AM</code>, if so, it subtracts curTime from 4AM, and sleeps for the reminder time(in seconds). But the subtraction isn't happening in seconds, it is numeric.</p>