shell关于日期的加减
$cat sh.sh #!/bin/bash if [ $# == 0 ] ; 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 [ $# == 1 ] ; then ydate=$1 ydateother=`date -d ${ydate} +"%Y-%m-%d"` tdate=`date -d "${ydate} 1days" +"%Y%m%d"` tdateother=`date -d ${tdate} +"%Y-%m-%d"` elif [ $# == 2 ] ; then ydate=$1 ydateother=`date -d ${ydate} +"%Y-%m-%d"` tdate=$2 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 -1 fi echo ${ydate}'--'${ydateother}'--'${tdate}'---'${tdateother}
传入字符串,修改为日期;
根据传入的字符串识别的日期,进行加减