I have such bash script:
array=( \'2015-01-01\', \'2015-01-02\' )
for i in \"${array[@]}\"
do
python /home/user/executeJobs.py {i} &> /home/user/
Bash is best written by leveraging pipes(|). This should result in memory efficient and concurrent(faster) processing. I would write the following:
seq 0 100 | xargs printf "20 Aug 2020 - %sdays\n" \
| xargs -d '\n' -l date -d
The following will print the date of 20 aug 2020 and print the dates of the 100 days before it.
This oneliner can be made into a utility.
#!/usr/bin/env bash
# date-range template
template="${1:--%sdays}"
export LANG;
xargs printf "$template\n" | xargs -d '\n' -l date -d
By default we choose to iterate into the past 1 day at a time.
$ seq 10 | date-range
Mon Mar 2 17:42:43 CET 2020
Sun Mar 1 17:42:43 CET 2020
Sat Feb 29 17:42:43 CET 2020
Fri Feb 28 17:42:43 CET 2020
Thu Feb 27 17:42:43 CET 2020
Wed Feb 26 17:42:43 CET 2020
Tue Feb 25 17:42:43 CET 2020
Mon Feb 24 17:42:43 CET 2020
Sun Feb 23 17:42:43 CET 2020
Sat Feb 22 17:42:43 CET 2020
Let's say we want to generate dates up to a certain date. We don't know yet how many iterations we need to get there. Let's say Tom was born 1 Jan 2001. We want to generate each date till a certain one. We can achieve this by using sed.
seq 0 $((2**63-1)) | date-range | sed '/.. Jan 2001 /q'
The
$((2**63-1))trick is used to create a big integer.
Once sed exits it will also exit the date-range utility.
One can also iterate using a 3 month interval:
$ seq 0 3 12 | date-range '+%smonths'
Tue Mar 3 18:17:17 CET 2020
Wed Jun 3 19:17:17 CEST 2020
Thu Sep 3 19:17:17 CEST 2020
Thu Dec 3 18:17:17 CET 2020
Wed Mar 3 18:17:17 CET 2021