bjghzly 发表于 2017-5-15 13:35:21

shell脚本 查看还有多少天过生日

  


read -p "Input your birthday(mm-dd):" birth
birth=`date +%Y`-$birth
date_birth=`date --date $birth +%s` #得到生日的秒值
date_now=`date +%s`      #得到当前时间的秒值
internal=$(($date_birth-$date_now))       #计算今日到生日日期的间隔时间
if [ "$internal" -lt "0" ]; then         #判断今天的生日是否已过
echo I am sorry.
else
echo There is $((internal/60/60/24)) days.       #输出结果,秒换算为天
fi
页: [1]
查看完整版本: shell脚本 查看还有多少天过生日