I want to store all possible dates between two user input dates. The input will be as like 20140605 and 20140830.
I want to store every date between the given dates into a variable using a loop so that I can use it.
The date generated or calculated must be in the same format as the input.
startdate=20141030
starttime=165800
enddate=20141120
endtime=175050
day=`expr $startdate % 100`
month=`expr $startdate % 10000`
year=`expr $startdate % 100000000`
month=`expr $month / 100`
year=`expr $year / 10000`
echo "$year $month $day"
while [ $enddate -ge $cdate ]
do
var=$cdate
#using variable var
if [ $day -eq 31 ]; then
cdate=`expr $cdate - $day`
day=1
((month++))
cdate=`expr $cdate + 100 + $day`
#cdate=`expr $cdate + $day`
if [ $month -eq 13 ]; then
#tmp=`expr $month \* 100`
cdate=`expr $cdate - $month \* 100`
month=1
((year++))
cdate=`expr $cdate + 10100`
if [ $year -eq 2999 ]; then
((year++))
echo $cdate
cdate=30010100
fi
fi
else
((day++))
((cdate++))
fi
if [ $enddate == $cdate ]; then
check=1
fi
done
I have tried to implement my requirement this way. But on compilation it says:
unary operator expected
What is the cause of this error, and how can I do this in a better way using a shell script?