I have script here that will list the date that the user will enter and output the date 5 days ago.
#!/bin/bash
echo "What month?"
echo "1 - January"
echo "2 - February"
echo "3 - March"
echo "4 - April"
echo "5 - May"
echo "6 - June"
echo "7 - July"
echo "8 - August"
echo "9 - September"
echo "10 - October"
echo "11 - November"
echo "12 - December"
echo ""
echo -n "What month? "
read m
if [ "$m" == "1" ]
then
mn="Jan "
elif [ "$m" == "2" ]
then
mn="Feb "
elif [ "$m" == "3" ]
then
mn="Mar "
elif [ "$m" == "4" ]
then
mn="Apr "
elif [ "$m" == "5" ]
then
mn="May "
elif [ "$m" == "6" ]
then
mn="Jun "
elif [ "$m" == "7" ]
then
mn="Jul "
elif [ "$m" == "8" ]
then
mn="Aug "
elif [ "$m" == "9" ]
then
mn="Sep "
elif [ "$m" == "10" ]
then
mn="Oct "
elif [ "$m" == "11" ]
then
mn="Nov "
elif [ "$m" == "12" ]
then
mn="Dec "
else
echo "Invalid month"
fi
echo ""
#DAY
echo -n "What day? "
read d
if [ "$d" -lt "9" ]
then
mnd="$mn"" ""$d"
elif [ "$d" -gt "31" ]
then
mnd="1"
else
mnd="$mn""$d"
fi
for dy in {0..4}; do
date -d "$mn $d - $dy days" +'%b %_d'
done
Output:
What month?
8
What day?
1
Aug 1
Jul 31
Jul 30
Jul 29
Jul 28
What I want now is to store each date in to variable for example
the first line must Aug 1 must be stored on variable x1
Jul 31 must be stored on variable x2 etc.. What I mean whatever output on the first list must be stored on x1 and so on.