I'd like to generate all permutations of letters up to length n
For example, for the argument 2 I'd like obtain a list like
a
aa
..
az
...
z
za
..
zz
I tried using a for loop to generate n increasingly larger brace expansions by repeating {a..z} ^1 and appending it to a variable. But this doesn't seem to work.
OUT=""
# loop from 1 to first argument
for ((i=1; i<=$1; i++))
do
OUT+=$(echo $(printf '{a..z}%.0s' {1..$i}))
done
OUT=$(echo $OUT | sort)
echo $OUT
Chained brace expansions don't scale well. You're better off with a function like this:
But if you insist on it, this is how you should do it: