2017-11-03 18 views
0
#!bash 
ARRAY=(one two three four five) 

繰り返しのないすべての組み合わせをリストし、配列は順序どおりではなく、出力は順不同である必要はありません。配列内のすべての値を比較します。

arr=(two four one three five) 
len=${#arr[*]} 

for ((i=0; i < $len; i++)); do 
    for ((j=$((i+1)); j < $len; j++)); do 
     echo "${arr[$i]} ${arr[*]:$j:1}" 
    done 
done 

出力:bashのforループで

所望の出力

one two 
one three 
one four 
one five 
two three 
two four 
two five 
three four 
three five 
four five 
+2

これはのように聞こえます宿題。何を試しましたか?それは働いていないのですか? – donjuedo

答えて

1

two four 
two one 
two three 
two five 
four one 
four three 
four five 
one three 
one five 
three five 
+0

ありがとうございました。 – nyitguy

+0

@nyitguy、ようこそ – RomanPerekhrest

関連する問題