#!/bin/bash
#Program:
# Input your birthday date and the program will calculate how many days before you birthday comes
#History:
# 2016/03/27 Linyimin First release
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
read -p "Input your birthday date(YYYYMMDD,ex -->20160327)" date1
if [ "$(echo $date1 | grep "[0-9]\{8\}")" == "" ];then
echo "Input error!"
exit 0
fi
#计算今天距1970年的时间秒数
declare -i date_today=$(date +%s --date=$(date +%Y%m%d))
declare -i date_input=$(date +%s --date=$date1)
declare -i date_diff=$(($date_input-$date_today))
if [ $date_diff -lt 0 ];then
date_diff=$(($date_today-$date_input))
declare -i days=$(($date_diff/60/60/24))
echo "Your birthday have passed $days days!"
exit 0
fi
days=$(($date_diff/60/60/24))
echo "There are also $days days when your birthday comes!"
exit 0
Bash Shell脚本:输入时间,输出距离你的生日天数
最新推荐文章于 2023-08-01 17:09:04 发布