Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Troubleshooting
Research
Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Syntax in ksh

Avatar of LuckyLucks
LuckyLucks asked on
Shell Scripting
5 Comments1 Solution451 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
Avatar of Tintin
Commented:
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answers