title: Shell Scripting to extract date
body: <p>Need a logic in shell scripting where I give the start and end date,
  say 
  <code>startDate=20140101</code> &amp; 
  <code>endDate=20160130</code></p>
  
  <p>I should be able to extract <code>startDate_new=20140122</code> and <code>endDate_new=20140221</code> in first loop.</p>
  
  <p>In next loop will need <code>startDate_new=20140222</code> and  <code>endDate_new=20140321</code> so on, till <code>startDate_new=20151221</code> &amp; <code>endDate_new=20160122</code> and exit out. Can you provide any shell scripting logic that can be used to achieve this. </p>
  
  <p>test.sh has,</p>
  
  <pre><code>startdate=2013-03-01
  enddate=2013-04-30
  
  curr="$startdate"
  while true; do
      echo "$curr"
      [ "$curr" \&lt; "$enddate" ] || break
      curr=$( date +%Y-%m-%d --date "$curr +1 day" )
  done
  </code></pre>
  
  <p>the above code prints,</p>
  
  <pre><code>2013-03-01
  2013-03-02
  2013-03-03
  2013-03-04
  2013-03-05
  2013-03-06
  2013-03-07
  2013-03-08
  .
  .
  .
  .
  2013-04-30
  </code></pre>
  
  <p>Can you help me how to extract the range I mentioned above ?</p>
  
  <p>Came up with a new logic,</p>
  
  <pre><code>startdate=2013-03-21
  enddate=2014-05-30
  
  curr="$startdate"
  while true; do
      [ "$curr" \&lt; "$enddate" ] || { echo "$curr"; break; }
      echo "$curr"
      curr=$( date +%Y-%m-%d --date "$curr +1 month" )
      end=$( date +%Y-%m-%d --date "$curr +1 month +1day" )
  done
  </code></pre>
  
  <p>the above logic gives</p>
  
  <pre><code>2013-03-21
  2013-04-21
  2013-05-21
  2013-06-21
  2013-07-21
  2013-08-21
  2013-09-21
  2013-10-21
  2013-11-21
  2013-12-21
  2014-01-21
  2014-02-21
  2014-03-21
  2014-04-21
  2014-05-21
  2014-06-21
  </code></pre>
  
  <p>Can you help with how to retrieve end date as 22nd of each month ?</p>