I am new to Bash so please help me articulate this question better if need be.
Let's say I have a .sh script. This script performs some calculation on some data for each day of the previous week from Sunday through Saturday (the week starts on Sunday). For e.g. Today, I am running this script for data starting 23rd Feb 2020 through 29th Feb 2020. When running the script on my terminal, I provide 3 parameters- year, month and day
./scriptname.sh ${yyyy} ${mm} ${dd} Now, most of the time, I am fine with something like this
yyyy=2020; mm=02; for dd in seq 23 -w 29; do ./scriptname.sh ${yyyy} ${mm} ${dd}; done But almost every month there is a week that spills over to the next month (e.g the week running from 29th March through 4th April). At first I thought I could automate this a little bit using variables
start_day=$(date -d "last-sunday -7 days" +%d); end_day=$(date -d "last-saturday" +%d); start_month=$(date -d "last-sunday -7 days" +%m); end_month=$(date -d "last-saturday" +%m); So the above script changes to something like this (had to exclude the backtick around seq for formatting sake)
yyyy=2020; for mm in ${start_month} ${end_month}; do for dd in seq -w ${start_day} ${end_day}; do ./scriptname.sh ${yyyy} ${mm} ${dd}; done; done But it creates all the permutations of dd and mm. How do I make sure I only pass these 7 relevant values for ${yyyy} ${mm} ${dd}?
2020 03 29 2020 03 30 2020 03 31 2020 04 01 2020 04 02 2020 04 03 2020 04 04
seq. Thenfor i in $(seq 1 5).