title: Calendar calculations in bash
body: <p>I want to do some calendar manipulations in bash - specifically, I want to figure out the last date of a given month (including leap-year, and a preparing a table for a lookup is not a valid solution for me).</p>
  
  <p>Supposedly I have the following code:</p>
  
  <pre><code>$year=2009
  $start_month=2
  $end_month=10
  for $month in $(seq $start_month $end_month); do
    echo "Last date of "$(date +"%B" -d "${year}-${month}-01")" is: " ???
  done
  </code></pre>
  
  <p>I can't figure out how to do something like this. I though <code>date -d</code> would work like POSIX mktime and fold invalid dates to their valid equivalents, so I could say something like <code>date -d "2009-03-00"</code> and get '2009-02-28', but no such luck.</p>
  
  <p>Is there anyway to do it using only what is available on bash in a standard GNU environment?</p>