Loading
View RSS Feed

Goldsonam's Blog

How To Implement Leap Year Program In Shell Scripting?

Rating: 5 votes, 4.20 average.
A simple program in shell scripting to help users get familiar with its syntax.

Code:
Code:
echo "ENTER THE YEAR"
read a
b='expr $a % 4'
c='expr $a % 100'
d='expr $a % 400'
if [ $c -eq 0]
  then
   if [ $d -eq 0]
     then
              echo " THIS YEAR IS A CENTURY LEAP YEAR"
    else
              echo " THIS YEAR NOT IS A  LEAP YEAR"
  fi

else
   if [ $b -eq 0]
     then
              echo " THIS YEAR IS A CENTURY LEAP YEAR"
    else
              echo " THIS YEAR NOT IS A  LEAP YEAR"

  fi
fi

Submit "How To Implement Leap Year Program In Shell Scripting?" to Digg Submit "How To Implement Leap Year Program In Shell Scripting?" to del.icio.us Submit "How To Implement Leap Year Program In Shell Scripting?" to StumbleUpon Submit "How To Implement Leap Year Program In Shell Scripting?" to Google

Updated 03-04-2011 at 01:23 PM by goldsonam

Categories
Unix

Comments

  1. Unregistered's Avatar
    There mus t be space before the ] in if condition. Otherwise it will show an error and will erroneous ouput
  2. infosec's Avatar
    #!/bin/sh

    a=0
    echo "ENTER THE YEAR"
    read a
    b=$(($a % 4))
    c=$(($a % 100))
    d=$(($a % 400))


    if [ $c -eq 0 ]; then
    if [ $d -eq 0 ]
    then
    echo "$a, THIS YEAR IS A CENTURY LEAP YEAR"
    else
    echo "$a, THIS YEAR NOT IS A LEAP YEAR"
    fi

    else
    if [ $b -eq 0 ]; then
    echo "$a, THIS YEAR IS A CENTURY LEAP YEAR."
    else
    echo "$a, THIS YEAR NOT IS A LEAP YEAR."

    fi
    fi
  3. prasecure's Avatar
    Thanks for a Updated leap year script.



Disclaimer: Users of techforum4u.com are responsible for ensuring that any material they post (article, blog posts, images or other mulitimedia content) does not violate or infringe upon the copyright, patent, trademark, or any personal or proprietary rights of any third party, and is posted with the permission of the owner of such rights.Anyone who violates these rules may have their access privileges removed without warning.