Bash Shell脚本:输入时间,输出距离你的生日天数

#!/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

评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值