首页 > 试题广场 >

请自行建立一支程序,该程序可以用来计算『你还有几天可以过生日

[问答题]
请自行建立一支程序,该程序可以用来计算『你还有几天可以过生日』啊?
#!/bin/bash
read -p "please input your birthday(MMDD,ex>1029): "bir
now=`date +%m%d`
if [ "$bir" == "$now" ]; then
echo "Happy Birthday to you!!!"
elif [ "$bir" -gt "$now" ]; then
year=`date +%Y`
total_d=$(($((`date --date="$year$bir" +%s`-`date +%s`))/60/60/24))
echo "Your birthday will be $total_d later"
else
year=$((`date +%Y`+1))
total_d=$(($((`date --date="$year$bir" +%s`-`date +%s`))/60/60/24))
echo "Your birthday will be $total_d later"
fi
发表于 2020-12-10 10:48:37 回复(0)