Reputation: 21
Here is some of the code, I tried. I need to get past 6 months data (year & Month) based on the entered year and month.
Input and Output format:-
*/example program:
please enter year:2019
please enter month:05
output:
201904
201903
201902
201901
201812
201811/*
My Script:
if [ -z $1 ]
then
echo Please enter year.
exit
fi ,
if [ -z $2 ]
then
echo Please enter month
exit
fi ,
x=0
while [ "$x" -le 12 ]
do
year= date +'%Y%m' -d "$x month ago"
echo $year
((x++))
Upvotes: 2
Views: 1000
Reputation: 2715
try
date --date="$1-$2-01 -6 month" +%B
Demo:
date --date="2019-05-01 -6 month" +'6 month from date was %B!'
6 month from date was November!
Upvotes: 1