shlogg · Early preview
Jacopo Valanzano @jacopovalanzano

Bash Script Generates All Permutations Of Characters

Bash script generates all possible permutations of characters from a given charset (0-9, a-z, A-Z). Uses recursion to build permutations. Usage: `permute 2` outputs all 2-character combinations.

A simple Bash script to generate all possible permutations of characters from a given character set, in this case 0 to 9 and a to z (capital and lower-case sets):

charset=({a..z} {A..Z} {0..9});
permute(){
  (($1 == 0)) && { echo "$2"; return; }
  for char in "${charset[@]}"
  do
    permute "$((${1} - 1 ))" "$2$char"
  done
}
permute "$1"

    
    

    
    



Usage: root@root:~# permute 2