Syntax in ksh


 I get the following error :  syntax error at line 10 : `else' unmatched

My code looks like. It returns the last day of the month so its a 30,31 for most or 28 or 29 for Feb depending upon whether its a leap year. Any ideas?

#! /usr/bin/ksh
y=`date +"%Y"`
m=`date +"%m"`
d=`date +"%d"`
if [[ $m == 01 || $m == 03 || $m == 05 || $m == 07 || $m == 08 || $m == 10 ||
$m == 12 ]]
then endD=31;
else if [[ $m == 02 ]]
  leapyr=`expr $y%4`;
  if [[ $leapyr -eq 0 ]]
echo $y
echo $m
echo $endD
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Much quicker and easier to do
cal|awk 'END{print DAY};{if (NF<1) {next};DAY=$NF}'

Open in new window

LuckyLucksAuthor Commented:
Its for the last month's end date
Your original code was trying to get the last date from the current month.

What Unix/Linux system are you trying to do this on?
LuckyLucksAuthor Commented:
unix AIX 5.3
Sorry my wording was off, am looking for the last day of previous month
So long as you have GNU date on your system (you can easily install it if you need to)

The following will output the last day of the previous month.  

date -d "$(date -d "$(date +%Y-%m-%d) -1 month" +%Y-%m-01) +1 month -1 day" +%d

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.