linux shell 突破
targetDate=$(cat maxdayid); targartMonth=${targetDate:4:2}; targartYear=${targetDate:0:4}; echo $targartMonth; date +%Y-%m-%d >>curDate ; curDate=$(cat curDate); curMonth=${curDate:5:2}; echo $curMonth; sql='SELECT * FROM t_stock_' union=" union all " sql_where=" where dayid>\'$targetDate\'" #去零前缀 targartMonth if [ ${targartMonth:0:1} = '0' ] ; then targartMonth=${targartMonth:1:1} echo $targartMonth fi #去零前缀 curMonth if [ ${curMonth:0:1}='0' ] ; then curMonth=${curMonth:1:1} echo $curMonth fi rm -f stock_sql #stock_sql echo "[Global]" >>stock_sql lsql="" if [ $targartMonth -eq $curMonth ]; then echo select adfdfd from stcok$targartYear$curMonth >>stock_sql else while [[ $curMonth -ge $targartMonth ]];do echo $targartMonth; if [ $targartMonth -eq $curMonth ]; then #lsql=$lsql$sql$targartYear$targartMonth if [ $targartMonth -ge 10 ]; then lsql=$lsql$sql$targartYear$targartMonth$sql_where else lsql=$lsql$sql$[targartYear]0$targartMonth$sql_where fi else if [ $targartMonth -ge 10 ]; then lsql=$lsql$sql$targartYear$targartMonth$sql_where$union else lsql=$lsql$sql$[targartYear]0$targartMonth$sql_where$union fi fi echo $lsql targartMonth=$[targartMonth+1] done; fi echo $sql #写入文件 echo '$$sql=' "'$lsql'" >>stock_sql
posted on 2017-09-01 16:46 HelloHongfu 阅读(160) 评论(0) 编辑 收藏 举报