SHELL 循环获取日期以及FOR使用
for((i=1;i<=10;i++)); do PYTHONPATH=lib/ bin/cupid -c conf/config.cfg -u http://shop33220311.taobao.com/?tbpm=4 -s test/ -p xx; sz test/xx_*; done;
数组遍历:
SQL[0]=" DELETE FROM sight_area;" SQL[1]=" insert into public.sight_area(area_id,name,name_pinyin,area_path,type) select id,name,name_pinyin,area_path,type from mirror.sight where type not in ('景区','景点');" #循环遍历执行SQL for i in "${!SQL[@]}" do echo "${SQL[$i]}" | /opt/pg93/bin/psql -h l-tdata1.tkt.cn6.qunar.com -U pdata -s log_analysis done
简单的遍历数组
如数组:array=(element1 element2 element3 .... elementN)
for data in ${array[@]} do echo ${data} done
循环获取时间
#!/bin/bash startDay="2014-01-01" endDay="2014-12-31" while [ $startDay != $endDay ] do echo ${startDay}; startDay=`date -d "+1 day ${startDay}" +%Y-%m-%d` #关键步骤,获取第二天的时间 done
嵌套循环获取时间
#!/bin/bash start="2013-03-10" end="2013-03-14" platforms=("a" "b" "c" "d") date=$start tomo() { echo `date +%Y-%m-%d -d "$1 1 days"`; } end="`tomo $end`" while [ "$date" != "$end" ] do echo $date for p in ${platforms[*]} do echo $p #///todo done date="`tomo $date`" done
输出:
2013-03-10 a b c d 2013-03-11 a b c d 2013-03-12 a b c d 2013-03-13 a b c d 2013-03-14 a b c d