Skip to main content
3 of 3
added 78 characters in body
ilkkachu
  • 147.9k
  • 16
  • 268
  • 441

In Bash or something that supports arrays, you could put the character set in an array and loop over the array again, prepending the characters again:

chars=( {a,b,c} )
doubles=()
triplets=()
for c in "${chars[@]}" ; do 
    doubles+=( ${chars[@]/#/$c} )
done
for c in "${chars[@]}" ; do 
    triplets+=( ${doubles[@]/#/$c} )
done
echo "${triplets[@]}"

that prints aaa aab aac ... ccc, and you can repeat as necessary for the longer ones, or turn it into a recursive function. (The ${var//} is a pattern substitution where # marks the start of the string. When it's applied to an array, it applies to all values of the array, one at a time.)

ilkkachu
  • 147.9k
  • 16
  • 268
  • 441