A leap year comes once every four years. It is the year when an extra day is added to the Gregorian calendar used by most of the world.

An ordinary year has 365 days. A leap year has 366 days. The extra day is added to the month of February. In an ordinary year, February has 28 days. In a leap year, it has 29 days. This extra day is called a leap day.

How do I find out leap year?

A year is a leap year if it can be evenly divided by four. For example, 1996 was a leap year. But a year is not a leap year if can be evenly divided by 100 and not by 400. This is why 1700, 1800, 1900 were not leap years, but 2000 was.

Shell script to determine if entered year is leap or not…

# Shell program to read any year and find whether leap year or not
# -----------------------------------------------
# Copyright (c) 2005 nixCraft project <http://cyberciti.biz/fb/>
# 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
echo -n "Enter year (yyyy) : "
read yy
# 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
elif [ $((yy % 100)) -eq 0 ] ; then
   : # not a leap year do nothing and use old value of isleap
   # it is a leap year
if [ "$isleap" == "true" ];
   echo "$yy is leap year"
   echo "$yy is NOT leap year"
🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source, and DevOps topics via:
Category List of Unix and Linux commands
Disk space analyzers df ncdu pydf
File Management cat tree
Firewall Alpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilities NetHogs dig host ip nmap
OpenVPN CentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Manager apk apt
Processes Management bg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searching grep whereis which
User Information groups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPN Alpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
1 comment… add one
  • Roel Pompen Aug 20, 2015 @ 12:26


    # Get current year
    YEAR=$(date +%Y)

    # A year divisible by 4 is a leap year only when: OR the year’s NOT divisible by 100
    # OR IS divisible by 400.
    # Implemented according to most efficient short circuit evaluation.
    if $(( (YEAR % 4) == 0 )) &then
    echo “$YEAR is a leap year.”
    echo “$YEAR is not a leap year.”

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.