2017-10-13 16 views
0

bashスクリプトの次の部分を実行すると、内部配列をループする前にoutter配列をループしています。内側ループを実行する前に外側ループを実行するbashネストループ

0 -- 0 
PROJ-198 
PN/PROJ-16114/PROJ-1233_curl.log:["fields","issuelinks",0,"outwardIssue","fields","status","name"] "Closed" 
PN/PROJ-16114/PROJ-188_curl.log:["fields","issuelinks",0,"outwardIssue","fields","status","name"] "Closed" 
PN/PROJ-16114/PROJ-198_curl.log:["fields","issuelinks",0,"outwardIssue","fields","status","name"] "Closed" 
PN/PROJ-16114/PROJ-204_curl.log:["fields","issuelinks",0,"outwardIssue","fields","status","name"] "Closed" 
PN/PROJ-16114/PROJ-209_curl.log:["fields","issuelinks",0,"outwardIssue","fields","status","name"] "Closed" 
PN/PROJ-16114/PROJ-1371_curl.log:["fields","issuelinks",0,"outwardIssue","fields","status","name"] "On Hold" 

0 1 2 3 4 5 -- 0 1 2 3 4 5 
PROJ-186 
PN/PROJ-16114/PROJ-16114_curl.log:["fields","issuelinks",0,"outwardIssue","fields","status","name"] "Closed" 
PN/PROJ-16114/PROJ-1142_curl.log:["fields","issuelinks",0,"outwardIssue","fields","status","name"] "Closed" 
PN/PROJ-16114/PROJ-172_curl.log:["fields","issuelinks",0,"outwardIssue","fields","status","name"] "Closed" 
PN/PROJ-16114/PROJ-180_curl.log:["fields","issuelinks",0,"outwardIssue","fields","status","name"] "Closed" 
PN/PROJ-16114/PROJ-182_curl.log:["fields","issuelinks",0,"outwardIssue","fields","status","name"] "Closed" 
PN/PROJ-16114/PROJ-185_curl.log:["fields","issuelinks",0,"outwardIssue","fields","status","name"] "Closed" 
PN/PROJ-16114/PROJ-186_curl.log:["fields","issuelinks",0,"outwardIssue","fields","status","name"] "Closed" 
PN/PROJ-16114/PROJ-187_curl.log:["fields","issuelinks",0,"outwardIssue","fields","status","name"] "Closed" 
PN/PROJ-16114/PROJ-188_curl.log:["fields","issuelinks",0,"outwardIssue","fields","status","name"] "Closed" 
PN/PROJ-16114/PROJ-198_curl.log:["fields","issuelinks",0,"outwardIssue","fields","status","name"] "Closed" 
PN/PROJ-16114/PROJ-204_curl.log:["fields","issuelinks",0,"outwardIssue","fields","status","name"] "Closed" 
PN/PROJ-16114/PROJ-209_curl.log:["fields","issuelinks",0,"outwardIssue","fields","status","name"] "Closed" 
PN/PROJ-16114/PROJ-1371_curl.log:["fields","issuelinks",0,"outwardIssue","fields","status","name"] "On Hold" 
PN/PROJ-16114/PROJ-16114_curl.log:["fields","issuelinks",1,"outwardIssue","fields","status","name"] "Closed" 
PN/PROJ-16114/PROJ-172_curl.log:["fields","issuelinks",1,"outwardIssue","fields","status","name"] "Closed" 
PN/PROJ-16114/PROJ-180_curl.log:["fields","issuelinks",1,"outwardIssue","fields","status","name"] "Closed" 
PN/PROJ-16114/PROJ-182_curl.log:["fields","issuelinks",1,"outwardIssue","fields","status","name"] "Closed" 
PN/PROJ-16114/PROJ-185_curl.log:["fields","issuelinks",1,"outwardIssue","fields","status","name"] "Closed" 
PN/PROJ-16114/PROJ-186_curl.log:["fields","issuelinks",1,"outwardIssue","fields","status","name"] "Closed" 
PN/PROJ-16114/PROJ-187_curl.log:["fields","issuelinks",1,"outwardIssue","fields","status","name"] "Closed" 
PN/PROJ-16114/PROJ-188_curl.log:["fields","issuelinks",1,"outwardIssue","fields","status","name"] "Closed" 
PN/PROJ-16114/PROJ-200_curl.log:["fields","issuelinks",1,"outwardIssue","fields","status","name"] "Deployed" 
PN/PROJ-16114/PROJ-201_curl.log:["fields","issuelinks",1,"outwardIssue","fields","status","name"] "Deployed" 
PN/PROJ-16114/PROJ-16114_curl.log:["fields","issuelinks",2,"outwardIssue","fields","status","name"] "Closed" 
PN/PROJ-16114/PROJ-180_curl.log:["fields","issuelinks",2,"outwardIssue","fields","status","name"] "Closed" 
PN/PROJ-16114/PROJ-182_curl.log:["fields","issuelinks",2,"outwardIssue","fields","status","name"] "Closed" 
PN/PROJ-16114/PROJ-185_curl.log:["fields","issuelinks",2,"outwardIssue","fields","status","name"] "Closed" 
PN/PROJ-16114/PROJ-186_curl.log:["fields","issuelinks",2,"outwardIssue","fields","status","name"] "Closed" 
PN/PROJ-16114/PROJ-198_curl.log:["fields","issuelinks",2,"outwardIssue","fields","status","name"] "Deployed" 
PN/PROJ-16114/PROJ-199_curl.log:["fields","issuelinks",2,"outwardIssue","fields","status","name"] "Deployed" 
PN/PROJ-16114/PROJ-209_curl.log:["fields","issuelinks",2,"outwardIssue","fields","status","name"] "Closed" 
PN/PROJ-16114/PROJ-16114_curl.log:["fields","issuelinks",3,"outwardIssue","fields","status","name"] "Closed" 
PN/PROJ-16114/PROJ-182_curl.log:["fields","issuelinks",3,"outwardIssue","fields","status","name"] "Closed" 
PN/PROJ-16114/PROJ-186_curl.log:["fields","issuelinks",3,"outwardIssue","fields","status","name"] "Closed" 
PN/PROJ-16114/PROJ-209_curl.log:["fields","issuelinks",3,"outwardIssue","fields","status","name"] "Deployed" 
PN/PROJ-16114/PROJ-16114_curl.log:["fields","issuelinks",4,"outwardIssue","fields","status","name"] "Closed" 
PN/PROJ-16114/PROJ-186_curl.log:["fields","issuelinks",4,"outwardIssue","fields","status","name"] "Closed" 
PN/PROJ-16114/PROJ-16114_curl.log:["fields","issuelinks",5,"outwardIssue","fields","status","name"] "Closed" 
PN/PROJ-16114/PROJ-186_curl.log:["fields","issuelinks",5,"outwardIssue","fields","status","name"] "Deployed" 

0 -- 0 
PROJ-209 
PN/PROJ-16114/PROJ-16114_curl.log:["fields","issuelinks",0,"outwardIssue","fields","status","name"] "Closed" 
PN/PROJ-16114/PROJ-1142_curl.log:["fields","issuelinks",0,"outwardIssue","fields","status","name"] "Closed" 
PN/PROJ-16114/PROJ-172_curl.log:["fields","issuelinks",0,"outwardIssue","fields","status","name"] "Closed" 
PN/PROJ-16114/PROJ-180_curl.log:["fields","issuelinks",0,"outwardIssue","fields","status","name"] "Closed" 
PN/PROJ-16114/PROJ-1371_curl.log:["fields","issuelinks",0,"outwardIssue","fields","status","name"] "On Hold" 

はおそらく、単にいくつかの愚かな過ちを犯して:

for i in "${linkedTickets[@]}" 
    do 
     array=($(cat ${WORKDIR}/${i}_curl.log | 
       egrep 'Depend' | 
       sed 's/depends on//g; s/[][\"[:space:]]//g; s/fields,//g; s/issuelinks,//g; s/,type//g; s/,outward//g; s/outwarddependson//g; s/,name//g; s/Depend//g;' | tr -d '\040\011\015' | tr '\n' ' ')) 
     var=$i 
     if [ ${#array[@]} -ne 0 ]; then 
       echo "" 
       echo "${!array[@]} -- ${array[@]}" 
       echo "$var" 
       for j in "${array[@]}" 
       do 
         cat "$WORKDIR/${var}_curl.log" | 
           grep -R "\[\"fields\",\"issuelinks\",${j},\"outwardIssue\",\"fields\",\"status\",\"name\"\]" | 
           sort -u 
       done 
     fi 
done 

出力は次のようになります。しかし、私がここで何をしているのかについての背景は、私はJIRチケットをこのbashスクリプトに渡しています。これは、Atlassianのバージョン2 API経由でチケットをカールし、上記のJSONを解析して、リンクされたTheTickets [@]にそれらを投げ、スクリプトで何回か繰り返してそれらのチケットをカールさせてカールログを生成させ、一度私が依存関係を探していたら、上記の2つのループが問題になりますissuelink#を検索してそのチケットの欲求を調べるだけですが、$ iを1回だけではなく、$ jのループ内でループしています。 。これは、内部でwhileループを使用する必要があるときにforループを使用する場合ですか?

0 -- 0 
PROJ-189 
PN/PROJ-16114/PROJ-189_curl.log:["fields","issuelinks",0,"outwardIssue","fields","status","name"] "Closed" 
0 -- 0 
PROJ-195 
PN/PROJ-16114/PROJ-195_curl.log:["fields","issuelinks",0,"outwardIssue","fields","status","name"] "Closed" 
0 -- 0 
PROJ-200 
PN/PROJ-16114/PROJ-200_curl.log:["fields","issuelinks",0,"outwardIssue","fields","status","name"] "Closed" 
0 -- 0 
PROJ-209 
PN/PROJ-16114/PROJ-16114_curl.log:["fields","issuelinks",0,"outwardIssue","fields","status","name"] "Closed" 

私はそれが非常におそらく最高の状態で間違ったラフだと確信していて、うまくいけば、私は私の構文のために一生懸命に打たないであろう、任意のフィードバックをお待ちしております。

答えて

0

ループ入力を引用符で囲みます。

for i in "${a[*]}"; do echo $i; done 
1 2 3 

for i in ${a[*]}; do echo $i; done 
1 
2 
3 
関連する問題