Leap year K-shell script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Leap year K-shell script
# 1  
Old 06-14-2005
Leap year K-shell script

I need a k-shell script that tests for leap-year. Does anyone have one at hand, need ASAP!!!
# 2  
Old 06-14-2005
Code:
#!/usr/bin/ksh
year=$1
if [ `expr $year % 100` -eq 0 -a `expr $year % 400` -eq 0 ]
then
        echo "$year is a leap year"
elif [ `expr $year % 100` -ne 0 -a `expr $year % 4` -eq 0 ]
then
        echo "$year is a leap year"
else
        echo "$year is a not leap year"
fi

Cheers!

Last edited by blowtorch; 06-14-2005 at 05:12 PM.. Reason: add code tags
# 3  
Old 11-18-2008
yeah, I know it's an old thread, but I found this useful and I just wanted to post this one. Squirrel this away in your script, or even your .profile, and then let the system do it for you with a simple call to leap():

Code:
function leap 
{
#  This function tells you if the argument is a leap year or not... 
if [[ $(cal ${1:-$(date '+%Y')} |egrep "^[ 0-9][0-9]| [ 0-9][0-9]$" |wc -w) -eq 365 ]] 
then 
        Leap_YN='N' 
else
        Leap_YN='Y'
fi && print ${Leap_YN} 
}


Last edited by curleb; 01-30-2009 at 11:15 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script rm last 1 year file

HI I am using below script to remove only last year files and also need deleted files i want to keep in log file or history for future reference But it is giving wrong output please help or let me any other way for example 2016 if am using this command it is removing 2016 and 2017 files also... (2 Replies)
Discussion started by: Kalia
2 Replies

2. Solaris

Leap second for year 2015

I hear the Leap second for 2015 will occur on June 30 at 23:59:60 according to the wild rumours from internet the expected impact ranges from crashing to hanging servers. Can anybody share their preparations what they have done for solaris servers? are there any patches to install or workaround?... (1 Reply)
Discussion started by: sparcguy
1 Replies

3. Shell Programming and Scripting

How to pass current year and month in FOR LOOP in UNIX shell scripting?

Hi Team, I have created a script and using FOR LOOP like this and it is working fine. for Month in 201212 201301 201302 201303 do echo "Starting the statistics gathering of $Month partitions " done But in my scripts the " Month " variable is hard-coded. Can you please any one... (3 Replies)
Discussion started by: shoan
3 Replies

4. Fedora

Leap second happening

Have anybody heard about the Leap second problem Leap second :A leap second is a one-second adjustment that is occasionally applied to Coordinated Universal Time (UTC) in order to keep its time of day close to the mean solar time. How could i avoid such thing in my script which i deal with... (6 Replies)
Discussion started by: wnaguib
6 Replies

5. Shell Programming and Scripting

unix korn shell leap years problem

Write a function called dateToDays that takes three parameters -a month string such as Sep, a day number such as 18, and a year number such as 1962-and return s the number of days from January 1, 1900, to the date. Notes: I am asking you to account for leap years. my script is not... (0 Replies)
Discussion started by: babuda0059
0 Replies

6. UNIX for Dummies Questions & Answers

Number of leap seconds

Is there a function call in std library or unit command that returns the number of current leap seconds? GG (4 Replies)
Discussion started by: NAVTime
4 Replies

7. Shell Programming and Scripting

shell script to find and copy the files creted in the year 2006 to another directory

Hi All, I am new to UNIX. I will be thankful if some one helps me. I have to write a shell script for one of the requirement. I have files created from Jan 2006 to March 2008. My requirement is to write a script in such a way that 1) To find and copy(not Moving) the files created in the... (2 Replies)
Discussion started by: manas6
2 Replies

8. UNIX for Advanced & Expert Users

leap seconds and the stdc library

I understand the NTP protocol, so keeping system time updated is not a problem. Standard C library routines like localtime() take a number of UTC seconds elapsed since the start of the epoch (Jan 1, 1970). These times in seconds can be a filetime, system time, or some other time in the past or... (1 Reply)
Discussion started by: jim mcnamara
1 Replies

9. HP-UX

Leap Second

Hi All, We are running the HP-UX 11.11 and Linux AS 3.0. so, shall we need to make any changes for leap second i.e. insert the leap second on 1st Jan 2006 or does the system have some setup which would take care of this automatically. Please advise. Regards, Inder (1 Reply)
Discussion started by: isingh786
1 Replies

10. UNIX for Advanced & Expert Users

Insertion of Leap Second

Hi All, We are running the HP-UX 11.11 and Linux AS 3.0. so, shall we need to make any changes for leap second i.e. insert the leap second on 1st Jan 2006 or does the system have some setup which would take care of this automatically. Please advise. Regards, Inder (2 Replies)
Discussion started by: isingh786
2 Replies
Login or Register to Ask a Question