2013-10-10 29 views
0

我有結果的查詢過程值:UNIX shell腳本保存在一個變量

SELECT leg_store_wh_code || ',' || rms_location col1 from SKS_CNV_LOCATION_XREF as 

101,101 1,601 202,602 3,603 4,604 207,607 8,608 9,609 10,610 212,612 613,613 14,614 16,616 17,617 18,618 619,619 20,620 21,621 23,623 24,624 85,625 26,626 28,628 29,629 30,630 31,631 32,632 90,633 34,634 635,635 36,636(store_list_result holds this) 

我想使用循環內所有的值。但只有前值printing.its進行到下一values.Can誰能幫我

store_list="SELECT leg_store_wh_code || ',' || rms_location col1 from SKS_CNV_LOCATION_XREF ;" 
store_list_result=`sqlplus -s $UP <<EOF 

    SET FEEDBACK OFF 
    SET HEAD OFF 
    SET AUTOPRINT OFF 
    SET LINESIZE 1000 
    SET TAB OFF 
    SET ECHO OFF 
    SET PAGESIZE 0 
    SET TERMOUT OFF 
    SET TRIMSPOOL ON 

    ${store_list}   
exit 
     EOF` 
     for i in store_list_result 
     do 
     LEG_ID=`echo $store_list_result | cut -d',' -f1` 
     echo $LEG_ID 
     RMS_ID=`echo $store_list_result | cut -d',' -f2 | cut -d' ' -f1` 
     echo $RMS_ID 

結果我得到的是:

101 
101 

回答

1
for i in store_list_result do LEG_ID=`echo $store_list_result | cut -d',' -f1` 

它是如何以往任何時候都應該工作?你迭代一次($ i =「store_list_result」,而不是這個變量的值),然後你每次使用$ store_list_result(仍然是一次,但是它是錯誤的)。並正確地格式化你的代碼,嚴重的跡象正在被吃掉。