The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 04-23-2009
kodak kodak is offline
Registered User
  
 

Join Date: Jun 2003
Posts: 51
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 kind of cheats. If it's a negative number it assumes that it's after christmas and will just print the second line. you could do some more logic to make it return the actual number until the next christmas, but I didn't want to gum it up too much.