用shell scripts 脚本完成 计算"您还有几天就过生日"

先在此说明,我是个新手,自学的Linux shell编程.

以下是我的一点见解,觉得很不完善,希望高手们能够给予指导.

觉得应该可以用很简洁的办法解决这个问题.

#!/bin/bash
# Using brithday .......
#liyy 2010/12/30
declare date=`date`
echo "nowdate is $date"
echo `date|cut -c7-13`
now=`date|cut -c7-13`
nowmonth=`date|cut -c7-8`
echo "nowmonth==>$nowmonth"
nowday=`date|cut -c11-12`
echo "nowday==>$nowday"
declare -i birthmonth
declare -i birthday
echo "please input your birthmonth."
read birthmonth
echo "please input your birthday."
read birthday
declare -i ddmonth=`expr $birthmonth - $nowmonth`
declare -i ddday=`expr $birthday - $nowday`
echo "ddmonth==>$ddmonth"
echo "ddday==>$ddday"

if [ "$ddmonth" -eq "0" ]; then
   if [ "$ddday" -gt "0" ]; then
       echo "after $ddday day ,you will birthday"
   fi
elif [ "$ddmonth" -gt "0" ] && [ "$ddday" -gt "0" ]; then
   echo "after $ddmonth month + $ddday day will your birthday"
elif [ "$ddmonth" -gt "0" ] && [ "$ddday" -lt "0" ]; then
   echo "after `expr $ddmonth - 1` month+`expr 30 - $nowday + $birthday` day will your birthday"
else
   echo "this year your birthday is over ."
fi

你可能感兴趣的:(用shell scripts 脚本完成 计算"您还有几天就过生日")