I have to make a permutation in bash with \"eval\" and \"seq\" commands. So I have to make first a permutation that could contain the same numbers, then I have to filter it
I understand this isn't the seq+eval solution the OP wants but in case anyone in future is looking for an alternative, here's an implementation of the generate() function described in the Wikipedia article on Heap's Algorithm written in awk to solve this problem:
$ cat tst.awk
function generate(n,A, i) {
if (n == 1) {
output(A)
}
else {
for (i=0; i<(n-1); i++) {
generate(n-1, A)
swap(A, (n%2?0:i), n-1)
}
generate(n-1, A)
}
}
BEGIN{
if (n>0) {
for (i=1; i<=n; i++) {
A[i-1] = i
}
generate(n, A)
}
}
function output(a, i,g) {g=length(a); for (i=0;i
I stuck to the Wikipedia article naming and other conventions as much as possible, including starting the array at zero instead of the typical awk 1, for ease of comparison between that article and the awk code.