![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| countdown in unix? | JamieMurry | UNIX for Dummies Questions & Answers | 5 | 04-23-2009 07:15 PM |
| Display runnning countdown in a bash script? | Starcast | Shell Programming and Scripting | 11 | 04-02-2009 06:20 PM |
| Shuttleworth starts countdown to Ubuntu 8.04 release | iBot | UNIX and Linux RSS News | 0 | 04-17-2008 04:20 AM |
| Micro Countdown 1.0 (Default branch) | iBot | Software Releases - RSS News | 0 | 03-25-2008 09:30 PM |
| shell script - loop to countdown | froggwife | UNIX for Dummies Questions & Answers | 2 | 11-29-2001 10:48 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Code:
#!/bin/sh
XMAS=`date -d "Dec 25" +%j`
TODAY=`date +%j`
DAYS=$(($XMAS - $TODAY))
if [[ ! $DAYS =~ ^[0-9+$ ]]; then
echo There are $DAYS days left until Xmas.
else
echo Merry Xmas and Happy New year\!
fi
|
|
||||
|
This script uses Julian Days. This is overkill if you have GNU date (Linux)
Code:
#!/bin/ksh
jd=0
fraction=0
JD() # $1==day $2=month $3=year
{
day=$1
month=$2
year=$3
jd=0
if [[ $month -lt 3 ]] ; then
year=$(( $year - 1 ))
month=$(( $month + 12 ))
fi
a=$(( $year / 100 ))
b=$(( $a / 4 ))
c=$(( 2 - $a + $b ))
e=$(echo "365.25 * ( 4716 + $year ) " | bc -l)
f=$(echo "30.6001 * ( $month + 1)" | bc -l )
if [[ $year -gt 1581 ]] ; then
jd=$(( $c + $day + $e + $f ))
jd=$( echo "$jd - 1524.5" | bc -l )
fi
export jd
}
hr=$(( $(date "+%H") * 3600 ))
min=$(( $(date "+%M") *60 ))
sec=$(date "+%S")
fraction=$( echo "$hr/86400 + $min/86400 + $sec/86400"| bc -l)
JD $( date "+%d %m %Y" )
today=$( echo "$jd + $fraction" | bc -l)
yr=$( date "+%Y" )
JD 25 12 $yr
xmas=$jd
difference=$(( $xmas - $today ))
if [[ $difference -lt 0 ]] ; then
yr=$(( $yr + 1 ))
JD 25 12 $yr
xmas=$jd
difference=$(( $xmas - $today ))
fi
echo "Days to Christmas: $difference"
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|