1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #!/bin/sh set -e if [ $# -lt 1 ]; then echo "Start date missing" exit 1 fi if [ $1 = '-h' -o $1 = '--help' ]; then echo "date range generator" echo "Usage:" echo " Generate range from date until today:" echo " $ daterange 2019-01-01" echo echo " Generate range from date until end date:" echo " $ daterange 2018-12-27 2019-01-04" exit fi start=$(date -I -d $1) if [ $# -gt 1 ]; then end=$(date -I -d $2) else end=`date -I` fi while test $(echo "$start" | tr -d -) -le $(echo "$end" | tr -d -); do echo "$start" start=$(date -I -d "$start + 1 day") done |