First of all, i am glad your problem was solved. There are still some points you might want to consider:
ahem - no! You said (#1):
Just because you tried we do not have to try the same - after all, you didn't (at that time) have success with what you tried. We often have questions like how can i do X with tool Y where Y is something we positively know to be not suited at all for achieving X. (You wouldn't believe how often i have been asked something analogous to "please explain how i can solder this to that using a refrigerator and the collected works of Shakespeare".) Now, i admit this is not the case with your question but if you need the solution to be in awk, then please say so.
Like this, which is a valid reason to stick with awk. But since you didn't tell us you can hardly blame us for not knowing this, no?
Two things: first, yes, in some cases, but these were merely meant as demonstrations for using a certain method - in this case a certain little-known form of parameter expansion - and it was obvious how to adapt that for an set and any number of elements in the combination set. Addition is like 1 + 1 = 2 doesn't insinuate that i think "2 + 2" to work any different and of course i could say: addition is a commutative and associative operation on either sets of scalar elements or vector spaces .... Somehow, i noticed, though, that many people prefer the first over the second.
Second: in case of my function (#15) this isn't even true, because you can use any set and any number of elements from the set to build combinations. For instance this invocation:
perm ()
{
myset="$1"
n="$2"
buf=""
i=1
while (( i <= n )) ; do
buf="${buf}${myset}"
(( i++ ))
done
for x in $buf ; do echo $x ; done
return 0
}
perm "{1,a,2,b}" 5
will give you 1024 lines from "1111" to "bbbb". You could even call the function (i tried only in ksh93 but suppose it to work in bash too) with arbitrary strings like this:
# perm "{"ab","XY"}" 3
ababab
ababXY
abXYab
abXYXY
XYabab
XYabXY
XYXYab
XYXYXY
You definitely have a point there. As i am about to post a larger software project for the community within the next days i suggest we should have a discussion about coding standards in general. Perhaps we could all profit somewhat from such a discussion and by seeing what others do and why.
bakunin