Given (as an argument to my script) is a string of unique characters (e.g. "ABCDE") of which I need to get all permutations (or at least iterate over those permutations).
# SEG is one segment of the brace expansion (e.g. {A,B,C,D,E})
SEG="$(echo $1 | sed "s/\([^{}]\)/\1,/g" | sed "s/^\(.*\),$/{\1}/")"
# EXP is the full expansion (e.g. {A,B,C,D,E}{A,B,C,D,E}{A,B,C,D,E}{A,B,C,D,E}{A,B,C,D,E})
EXP="$(echo $1 | sed "s/./$SEG/g")"
I tried making a brace expansion out of that string to then just use for i in $EXP... or echo $EXP to get all permutations, much like how echo {A,B}{A,B} or for i in {A,B}{A,B}...would normally work.
The problem is that this way, I literally get {A,B,C,D,E}{A,B,C,D,E}{A,B,C,D,E}{A,B,C,D,E}{A,B,C,D,E} while I would like to get the full:
$ echo {A,B,C,D,E}{A,B,C,D,E}{A,B,C,D,E}{A,B,C,D,E}{A,B,C,D,E}
AAAAA AAAAB AAAAC AAAAD AAAAE AAABA AAABB AAABC AAABD AAABE AAACA AAACB AAACC AAACD AAACE...