Hi,
I have a string date to my unix script(sun solaris). I wanted to convert it into unix date so that I can use it in a conditional statement. Please see below:
MyTest.sh -s 2018-05-09
suppdt=$1 # string date passed via arguement as 2018-04-09
curryr=`date '+%Y'`
nextyr=`expr $curryr + 1`
StartDt_v=`echo "${curryr}-05-01"`
EndDt_v=`echo "${nextyr}-08-15"`
curryrfilename=test-import-data-${curryr}.txt
nextyrfilename=test-import-data-${nextyr}.txt
if [ ${suppdt} -ge ${StartDt_v} ] && [ ${suppdt} -le ${EndDt_v} ]; then
rm -f nextyrfilename;
else
echo " Do nothing"
fi
The issue is every time the conditional statement is evaluated it goes into else part of IF statement.
I think this might be happening due to the StartDt_v and EndDt_v
being a String date instead of proper Date variable. Would appreciate any advice from experts.
Thanks