Skip to content

Instantly share code, notes, and snippets.

@kyleparisi
Created January 20, 2017 18:15
Show Gist options
  • Save kyleparisi/7a9d1bb766b2696e7d4f9b3521f2995d to your computer and use it in GitHub Desktop.
Save kyleparisi/7a9d1bb766b2696e7d4f9b3521f2995d to your computer and use it in GitHub Desktop.
Bash script that loops over dates for other atomic scripts
#!/bin/bash
# On linux use date, on mac gdate [via `brew install coreutils`].
# Will run from oldest date to today.
# $ sh date_looper.sh '2016-12-10'
currentdate=$1
loopenddate=$(gdate --date "$2 1 day" +%Y-%m-%d)
until [ "$currentdate" == "$loopenddate" ]
do
echo $currentdate
# SOME_COMMAND_THAT_ACCEPTS_A_DAY $currentdate
# update current date to next day
currentdate=$(gdate --date "$currentdate 1 day" +%Y-%m-%d)
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment