1
#!bash
ARRAY=(one two three four five)

List all possible combinations with no repetition and array is not in order and the output does not need to be in order.

Desired output

one two
one three
one four
one five
two three
two four
two five
three four
three five
four five
1
  • 2
    This sounds like a homework assignment. What have you tried? Is it not working? Commented Nov 3, 2017 at 17:56

1 Answer 1

2

With bash for looping:

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 

The output:

two four
two one
two three
two five
four one
four three
four five
one three
one five
three five
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.