generate-string-case-combination.sh 616 B

12345678910111213141516171819202122232425262728
  1. #!/usr/bin/env bash
  2. set -euo pipefail # bash strict mode
  3. display_help(){
  4. echo "Usage: ${0##*/} [string]"
  5. exit 2
  6. }
  7. [[ $# -lt 1 ]] && display_help
  8. input=$1
  9. function generate_combinations {
  10. if [ ${#1} -eq 0 ]; then
  11. echo "$2"
  12. else
  13. char=${1:0:1}
  14. rest=${1:1}
  15. generate_combinations "$rest" "$2$char"
  16. generate_combinations "$rest" "$2${char^^}"
  17. if [[ "$char" =~ [[:alpha:]] ]] && [[ "${char,,}" != "${char^^}" ]]; then
  18. generate_combinations "$rest" "$2${char,}${rest^^}"
  19. generate_combinations "$rest" "$2${char^^}${rest,,}"
  20. fi
  21. fi
  22. }
  23. generate_combinations "$input" ""