Artificial intelligent assistant

Pairwise combinations of filenames If I have n files in a directory, for example; a b c How do I get pairwise combinations of these files (non-directional) to pass to a function? The expected output is a-b a-c b-c so that it can be passed to a function like fn -file1 a -file2 b fn -file1 a -file2 c ... * * * This is what I am trying out now. for i in *.txt do for j in *.txt do if [ "$i" != "$j" ] then echo "Pairs $i and $j" fi done done Output Pairs a.txt and b.txt Pairs a.txt and c.txt Pairs b.txt and a.txt Pairs b.txt and c.txt Pairs c.txt and a.txt Pairs c.txt and b.txt I still have duplicates (a-b is same as b-a) and I am thinking perhaps there is a better way to do this.

Put the file names in an array and run through it manually with two loops.

You get each pairing only once if if _j < i_ where _i_ and _j_ are the indexes used in the outer and the inner loop, respectively.


$ touch a b c d
$ f=(*)
$ for ((i = 0; i < ${#f[@]}; i++)); do
for ((j = i + 1; j < ${#f[@]}; j++)); do
echo "${f[i]} - ${f[j]}";
done;
done
a - b
a - c
a - d
b - c
b - d
c - d

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 385f2d94ddd0fc2640fda00ea0b9f5f9