12 January 2012

Shell Script to Find whether a year is Leap year or not

1 comment

Q. How do I write Shell Script to find leap year


echo -e "enter year "
read year
#if year is less than or equal to 0 then current year is assigned to year variable
if [ $year -le 0 ] ; then
year=`date | cut -d " " -f6`
if [ `expr $year % 400` -eq 0 ]; then
echo "$year is a Leap year"
elif [ `expr $year % 100` -eq 0 ]; then
echo "$year is not a Leap year"
elif [ `expr $year % 4 ` -eq 0 ]; then
echo "$year is not a Leap year"
echo "$year is not a leap year"


shell script to find leap year

Enjoy :)

If You Liked This Post Please Take a Time To Share This Post

You May Also Like...

1 comment: