#!/bin/sh
#  
#	Shell script to cutomize the date output 
#
#    options include -w = weekday
#     			     -m = month
#				     -t = time
#				     -d = day
#				     -y = year
#				     -z = timezone
#				     -o = output to a file
#
if [ $# -eq 0 ]
then
	/bin/date	
	exit 1
fi
FLAG='false'
OUTPUT=''
while getopts ":wmto:dyz" INPUT
do
	case $INPUT in
		w) OUTPUT="${OUTPUT} $(/bin/date | tr -s ' ' | cut -f1 -d ' ')";;
		m) OUTPUT="${OUTPUT} $(/bin/date | tr -s ' ' | cut -f2 -d ' ')";;
		d) OUTPUT="${OUTPUT} $(/bin/date | tr -s ' ' | cut -f3 -d ' ')";;
		o) FLAG='true'
		   FILE=${OPTARG};; 
		t) OUTPUT="${OUTPUT} $(/bin/date | tr -s ' ' | cut -f4 -d ' ')";;
		z) OUTPUT="${OUTPUT} $(/bin/date | tr -s ' ' | cut -f5 -d ' ')";;
		y) OUTPUT="${OUTPUT} $(/bin/date | tr -s ' ' | cut -f6 -d ' ')";;
		*) echo "error bad option ${OPTARG}"
	        exit 1;;
	esac
done
if [ $FLAG = 'true' ]
then
	echo "${OUTPUT}" > ${FILE}
else
	echo ${OUTPUT}
fi

CURRENT_DAY=$(/bin/date +"%j" | sed 's/^0*//')

echo "Only $((  365 - $CURRENT_DAY - 7 )) days until Christmas..."
echo "  did you remember the sweater for Aunt Betty?"

exit 0

