How 2 Know
If you can't Google it, You Can Knowing it.

Posts Tagged ‘leap’

Shell Script for Leap Year

Tuesday, July 30th, 2013

Hello every body,
i have below a nice script to tell year the year is Leap or NOT.just copy the following line into a new file name it leap.ksh

# Shell program to read any year and find whether leap year or not
# -----------------------------------------------
# Copyright (c) 2005 nixCraft project 
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
# store year
yy=0
isleap="false"
#echo -n "Enter year (yyyy) : "
#read yy
yy=$1
# find out if it is a leap year or not
if [ $((yy % 4)) -ne 0 ] ; then
   : #  not a leap year : means do nothing and use old value of isleap
elif [ $((yy % 400)) -eq 0 ] ; then
   # yes, it's a leap year
   isleap="true"
elif [ $((yy % 100)) -eq 0 ] ; then
   : # not a leap year do nothing and use old value of isleap
else
   # it is a leap year
   isleap="true"
fi
if [ "$isleap" == "true" ];
then
   echo "YES"
else
   echo "NOT"
fi

Continue Reading…