Problem: For parameters of a minimum and maximum date (ex: script.sh 20190801, 20201005) execute a function on each month within that date range. (ex: 20190801-20190831, 20190901-20190931 . . .)
Below is my current idea, but it fails in most cases
I get my expected results from passing, for example: 20190101 20201231 to the below code, but I'm unsure how to modify this to support something like 20190105 20200820
DateMin=$1 DateMax=$2 if [ $DateMin -ge $DateMax ]; then echo "ERROR: Minimum Date Cannot be above Maximum Date" exit fi let DateDelta=DateMax-DateMin for YearDelta in `seq $DateDelta -10000 0` do let TempDelta=$YearDelta-1130 for MonthDelta in `seq $YearDelta -100 $TempDelta` do let TempMin=$DateMax-$MonthDelta let TempMax=$DateMax-$MonthDelta+30 call_to_function $TempMin $TempMax done done
I created a repl.it here so it's easier to see: https://repl.it/repls/CanineAdmirableSeahorse#main.sh If you run "bash main.sh 20190101 20201231" that's the expected output.