Programming Tutorials

Check for leap year in Shell Script

By: Vivek G in Linux Tutorials on 2011-01-29  

This shell script accepts a year and checks if the entered year is leap year or not.
year=0

echo -n "Enter the year, I will tell you whether its Leap year or Not? "
read year

ans=$(($year % 4))  # or try ans=`expr $year % 2`

if [ $ans -eq 0 ]; then
   echo "$year is Leap Year"
else
   echo "$year is NOT Leap Year"
fi






Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in Linux )

Latest Articles (in Linux)