#!/bin/bash list1="one two three four five" for w1 in $list1; do list2="$(tr ' ' '\n' <<< $list1 | grep -v "$w1" | tr '\n' ' ')" for w2 in $list2; do list3="$(tr ' ' '\n' <<< $list2 | grep -v "$w2" | tr '\n' ' ')" for w3 in $list3; do list4="$(tr ' ' '\n' <<< $list3 | grep -v "$w3" | tr '\n' ' ')" for w4 in $list4; do list5="$(tr ' ' '\n' <<< $list4 | grep -v "$w4" | tr '\n' ' ')" for w5 in $list5; do echo "$w1 $w2 $w3 $w4 $w5" done done done done done