I have the following loop, but it doesn't stop and produces the wrong dates.
#!/bin/bash
i=0
thedate="2018-03-28"
enddate="2018-04-02"
while [ "$thedate" != "$enddate" ]; do
thedate=$( date -d "$thedate + $i days" +%F )
new_date=$( date -d "$thedate " +%Y%m%d )
printf 'The date is "%s"\n' "$new_date"
i=$(( i + 1 ))
done
I expected this output:
The date is "20180328"
The date is "20180329"
The date is "20180330"
The date is "20180331"
The date is "20180401"
The date is "20180402"
How can I achieve this?
set -xjust before the start of thewhileloop, and verify that your script is doing what you really think it's doing.