Shell Script to Check Leap Year
In this shell script program, we will learn to write:
shell script to check leap year or not
To solve leap year in shell script more easily, you have to know some basic concepts like:
Taking input from user.
LEAP YEAR RULES:
Every four years, a leap year come once. Per year contain 365.24 days but to correct and keep track of the solar calendar, we introduced leap year concept. Unlike regular years( 365 days), leap year has 366 days.
A year will be leap year if it is divided by 4 and if it’s remainder is equal to 0.
If above result is equal to 0, then we will consider that given year by the user is a leap year otherwise it is not.
ALGORITHM TO CHECK LEAP YEAR:
STEP 1: START SHELL SCRIPT
STEP 2: CLEAR THE SCREEN.
STEP 3: TAKE A YEAR INPUT BY THE USER.
STEP 4: IMPLEMENT IF-ELSE STATEMENT.
STEP 5: GIVE CONDITION #YEAR % 4
STEP 6: IF RESULT ==0 THEN IT IS LEAP YEAR OTHERWISER IT IS NOT
STEP 7: STOP SHELL SCRIPT
Shell script to check leap year or not
Given below is a shell script for checking leap year:
echo "LEAP YEAR SHELL SCRIPT"
echo -n "Enter a year:"
if [ `expr $year_checker % 4` -eq 0 ]
echo "$year_checker is a leap year"
echo "$year_checker is not a leap year"
LEAP YEAR SHELL SCRIPT
Enter a year:2020
2020 is a leap year
Would you like to see your article here on tutorialsinhand.
program by tutorialsinhand.com
About the Author
Page Views :
Published Date :