1week.sh
#!/bin/sh
#Loop from 7 to 1
for N in `seq 7 -1 1`
do
#From 7 days ago to 1 day ago
DATE=`date +%Y-%m-%d --date "${N} days ago"`
echo $DATE
done
Operation check environment: Ubuntu 20.04 LTS (Focal Fossa) + dash 0.5.10.2 + GNU coreutils 8.30 (date, seq)
$ ./1week.sh
2020-06-27
2020-06-28
2020-06-29
2020-06-30
2020-07-01
2020-07-02
2020-07-03
1week.sh
#!/bin/sh
#Loop from 7 to 1
for N in `seq 7 -1 1`
do
# -v-From 7d-v-Up to 1d
DATE=`date -v-${N}d +%Y-%m-%d`
echo $DATE
done
Operation check environment: macOS Catalina 10.15 + GNU bash 3.2.57 + BSD date + BSD seq
$ ./1week.sh
2020-06-27
2020-06-28
2020-06-29
2020-06-30
2020-07-01
2020-07-02
2020-07-03
Recommended Posts