1、输出时间格式 date
echo `date -d "today" +"%Y%m%d"`
echo `date -d " -1 day" +"%Y%m%d"`
注意:上面的”加号“和后面的”时间格式“之间不能够有空格。
2、shell时间循环
begin_date="20120529" end_date="20120621" echo "data process start ......." while [ $begin_date -le $end_date ] do begin_date=`date -d "$begin_date +1 day" +"%Y%m%d"` echo "---------------------------------------------------------" sleep 3 done echo "data process end ......."
方式二、
begin_date="2012-06-01"
end_date="2012-06-30"
while [ "$begin_date" \< "$end_date" -o "$begin_date" = "$end_date" ]
do echo $begin_date `awk -f date.awk 1.txt > 2.txt` begin_date=`date -d"$begin_date +1 day" +"%Y-%m-%d"` done