Logo 
Search:

Unix / Linux / Ubuntu Articles

Submit Article
Home » Articles » Unix / Linux / Ubuntu » Homework HelpRSS Feeds

Shell script which takes year as an input and displays whether it is leap year or not. If year is not provided then take current year as an input

Posted By: Scarlett Hughes     Category: Unix / Linux / Ubuntu     Views: 8219

Write a shell script, which receives any year as a argument and determines whether the year is leap or not. If no argument is supplied assume the current year as an argument.

Code for Shell script which takes year as an input and displays whether it is leap year or not. If year is not provided then take current year as an input in Unix / Linux / Ubuntu

val=$1
if [ $# -eq 0 ]
then
        val=`date | cut -f 6 -d " "`
fi

value=`echo $val % 4 | bc`
if [ $value -eq 0 ]
then
        echo "Leap year"else
        echo "Not leap year"
fi

-------------------------------------------------------------------
output
-------------------------------------------------------------------
Not leap year
  
Share: 



Scarlett Hughes
Scarlett Hughes author of Shell script which takes year as an input and displays whether it is leap year or not. If year is not provided then take current year as an input is from London, United Kingdom.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!