Skip to content

Instantly share code, notes, and snippets.

@ryanmjacobs
Last active May 19, 2021 12:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ryanmjacobs/4c02ad80f833dee0c307 to your computer and use it in GitHub Desktop.
Save ryanmjacobs/4c02ad80f833dee0c307 to your computer and use it in GitHub Desktop.
displays all upper/lowercase permutations of a word
#!/bin/bash
str=${1^^} # convert to uppercase
len=${#str} # get length of string
for ((perm=0; perm <= len; perm++)); do
for ((i=0; i <= len; i++)); do
lower=${str,,} # convert to lowercase
# Uppercase n-th letter for permutation
if [ $perm -gt 0 ]; then
nth=${lower:perm-1}
lower=$(echo ${lower:0:perm-1}${nth^})
fi
echo -n ${str:0:i} # print orig string from 0 to $i
echo ${lower:i} # print new string from $i to end
done
done | sort -u
@ryanmjacobs
Copy link
Author

Oh, and btw, this script is a complete failure.

I'm just keeping it here to prevent dead links.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment