DEV Community

Jacopo Valanzano
Jacopo Valanzano

Posted on

Character Permutations Using Bash

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"
Enter fullscreen mode Exit fullscreen mode

Usage: root@root:~# permute 2

Top comments (0)