How to get leap year for 2006-2015

Asked by celica MONTANEZ on 2012-09-12

How to use the cal command to determine which years between 2006 and 2015 are leap years.

Question information

Language:
English Edit question
Status:
Answered
For:
Ubuntu gnome-terminal Edit question
Assignee:
No assignee Edit question
Last query:
2012-09-12
Last reply:
2012-09-12
celica MONTANEZ (celimja) said : #1

I've tried cal -j 2006:2015 but cannot figure it out.

#!/bin/bash
# This script will test if we're in a leap year or not.

year=`date +%Y`

if [ $[$year % 400] -eq "0" ]; then
  echo "This is a leap year. February has 29 days."
elif [ $[$year % 4] -eq 0 ]; then
        if [ $[$year % 100] -ne 0 ]; then
          echo "This is a leap year, February has 29 days."
        else
          echo "This is not a leap year. February has 28 days."
        fi
else
  echo "This is not a leap year. February has 28 days."
fi

is a script that tests if the year of today is a leap year.

Can you help with this problem?

Provide an answer of your own, or ask celica MONTANEZ for more information if necessary.

To post a message you must log in.