【转】起始时间和终止时间,循环输出每天

 

$cat sh.sh
#!/bin/bash
#两个参数:起始时间和终止时间,循环输出每天
#输入格式:20171201 20171225
#输出格式:201712-01 2017-12-25
startdate=`date -d "+0 day $1" +%Y%m%d`
enddate=`date -d "+0 day $2" +%Y%m%d`

while [[ $startdate -le $enddate ]]
do
date=$startdate
startdateother=`date -d "+0 day $date" +%Y-%m-%d`
dateother=$startdateother
echo "$dateother"
startdate=`date -d "+1 day $date" +%Y%m%d`
startdateother=`date -d "+1 day $date" +%Y-%m-%d`
# write code here

done

 

【转自】:http://blog.csdn.net/Mark__cao/article/details/78012860

 

不同的格式。。。

posted @ 2017-12-25 19:31  宝山方圆  阅读(388)  评论(0编辑  收藏  举报