Last active
May 19, 2021 12:09
-
-
Save ryanmjacobs/4c02ad80f833dee0c307 to your computer and use it in GitHub Desktop.
displays all upper/lowercase permutations of a word
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oh, and btw, this script is a complete failure.
I'm just keeping it here to prevent dead links.