shell关于日期的加减

$cat sh.sh
#!/bin/bash if [ $# == ] ; then
ydate=`date -d -1days "+%Y%m%d"`
ydateother=`date -d -1days "+%Y-%m-%d"`
tdate=`date -d -0days "+%Y%m%d"`
tdateother=`date -d -0days "+%Y-%m-%d"`
elif [ $# == ] ; then
ydate=$
ydateother=`date -d ${ydate} +"%Y-%m-%d"`
tdate=`date -d "${ydate} 1days" +"%Y%m%d"`
tdateother=`date -d ${tdate} +"%Y-%m-%d"`
elif [ $# == ] ; then
ydate=$
ydateother=`date -d ${ydate} +"%Y-%m-%d"`
tdate=$
tdateother=`date -d ${tdate} +"%Y-%m-%d"`
else
echo "please do not input if calcute yedterday."
echo "please input like if calcute 20170510 one day: 20170510"
echo "please input like if calcute 20170510 and 20170512 two days : 20170510 20170511"
exit -
fi
echo ${ydate}'--'${ydateother}'--'${tdate}'---'${tdateother}

传入字符串,修改为日期;

根据传入的字符串识别的日期,进行加减

上一篇:$.grep()的用法


下一篇:overflow:hidden清除浮动原理