troubleshooting Question

Syntax in ksh

Avatar of LuckyLucks
LuckyLucks asked on
Shell Scripting
5 Comments2 Solutions451 ViewsLast Modified:

Hi,

 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 ]]
 then
  leapyr=`expr $y%4`;
  if [[ $leapyr -eq 0 ]]
   then
    endD=29;
   else
    endD=28;
  fi
 else
endD=30;
fi
 
echo $y
echo $m
echo $endD
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 2 Answers and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros