前月の末日を取得する (bash の小技)

bash で前月の末日が取得したい場合の小技。

day=$(date +'%d')
lastday=$(date -d "$day day ago" +'%Y-%m-%d')

echo $lastday