shell 计算日期

来源:百度知道 编辑:UC知道 时间:2024/05/29 00:21:48
待解决!!!

#!/bin/bash
# Program:
# Tring to calculate your demobilization date at how many days
# later...
# History:
# 2008/5/1 cc First release
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH //说明解释代码是用来做什么的。

echo "This prorgram will try to calculate :"
echo "How many days about your demobilization date..."
read -p "Please input your demobilization date (YYYYMMDD ex>20050401): " date2
date_d=`echo $date2 | grep '[0-9]\{8\}' ` //告诉用户程序的用途,并且说明应该如何输入日期格式

declare -i date_dem=`date --date="$date2" +%s`
declare -i date_now=`date +%s`
declare -i date_total_s=$(($date_dem-$date_now))
declare -i date_d=$(($date_total_s/60/60/24))
if [ "$date_total_s" -lt "0" ]; then
echo "You had been demobilization before: " $((-1*date_d)) " ago"
else
declare -i date