title: Iterating over a range of dates in a unix shell script
body: <p>I am trying to create a script in which 4 days ago date should be equal to to current date if it is not then add 1 more day and check. Below is the one i have created but still not clear about answer.</p>
  
  <hr>
  
  <pre><code>#!/bin/bash
  
  batchdate=`date --date "4 day ago" '+%Y%m%d'`
  matchdate=`date --date "today" '+%Y%m%d'`
  
  for i in {0..4}
  do
      if [ $batchdate != $matchdate &amp;&amp; $NEXT_DATE != $matchdate ]; then
  
     NEXT_DATE=$(date +%Y%m%d -d "$batchdate + $i day")
  
     echo "$NEXT_DATE"
  
     break
  
     fi
  
  done
  </code></pre>