Skip to content

Instantly share code, notes, and snippets.

@tkarna
Created June 26, 2019 05:16
Show Gist options
  • Save tkarna/3750dd1295ff6d28a98dc78470c4cfa7 to your computer and use it in GitHub Desktop.
Save tkarna/3750dd1295ff6d28a98dc78470c4cfa7 to your computer and use it in GitHub Desktop.
Loop through days of month in bash
#!/bin/bash
# loop through days of month given the first day
startdate="2019-06-01"
enddate=$(date -d "$startdate + 1 month" +"%Y-%m-%d")
ndays=$(( ($(date -d "$enddate" +%s) - $(date -d "$startdate" +%s) )/(60*60*24) ))
for i in $(seq 0 $(($ndays - 1)) ); do
date=$(date -d "$startdate + $i days" +"%Y-%m-%d")
echo $date
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment