2016-03-30 67 views
-1
currentDate="20160324" 
headerDumpFile="header.txt" 
#currentDate="$(date +’%Y%m%d’)" 
printf "Current date in dd/mm/yyyy format %s\n" $currentDate 

contId="" 
labelList="c12,playlist-play,play,pause,end,playlist-end,heartbeat,ns_st_cl" 

params="corporate=abc&user=abc&password=abc&startdate=$currentDate&site=abc&extralabels=$labelList" 
url="https://example.com/v1/start?$params" 

a=1 

while true 
do 
curl -D $headerDumpFile -v -k -H "Accept-Encoding:gzip" $url > $a.zip 
contId= cat $headerDumpFile | grep "X-CS-Continuation-Id:" | awk '{print $NF}' 

if [ "$contId" ];then 
    printf "Breaking the Loop.." 
    break; 
fi 
url="https://example.com/v1/start?$params&continuationId=${contId}" 
a=$((a + 1)) 
echo $contId 
echo $url 
done 

當我回顯url的contId的值作爲空白,但當我做echo $ contId。它打印正確,請您及時建議Bash Shell問題

+0

請寄出真實的腳本代碼,特別是設置被破壞的'contId'變量的行。 – jlliagre

+0

它正在while循環中設置..... – finch986

+0

它不是,看得更近。該變量在子文件(管道組件)中暫時被清除,當然不是真正的腳本想要做什麼。 – jlliagre

回答

0

也許是你想要達到的目標:

contId=$(cat $headerDumpFile | grep "X-CS-Continuation-Id:" | awk '{print $NF}') 

或者更簡單的:

contId=$(awk '/X-CS-Continuation-Id:/ {print $NF}' $headerDumpFile) 

注意,不像你猜是什麼,echo $contId不顯示代碼中的任何內容。顯示的是僞造的contId= cat $headerDumpFile | grep "X-CS-Continuation-Id:" | awk '{print $NF}'行的結果。

+0

no..its not working ... – finch986

+0

然後你的邏輯可能有缺陷。你應該告訴什麼包含'header.txt'。如果不知道這一點,很難走得更遠。 – jlliagre

+0

恐怕不是。你爲什麼要這麼做? – jlliagre