Created
May 23, 2021 21:04
-
-
Save gmolveau/92495da69ea36ce8f609ad52dcb32b3e to your computer and use it in GitHub Desktop.
spongebob meme bash function string converter
This file contains hidden or 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
#!/usr/bin/env bash | |
set -euo pipefail | |
input="$*" | |
length="${#input}" | |
charindex=0 | |
spongebob_str="" | |
while [ $charindex -lt $length ]; do | |
char="${input:$charindex:1}" | |
if ! [[ $char == [[:space:]] ]]; then | |
# 50% chance to convert | |
if [ $(($RANDOM % 10)) -lt 5 ]; then | |
char="$(echo ${char} | tr '[[:lower:]]' '[[:upper:]]')" | |
else | |
char="$(echo ${char} | tr '[:upper:]' '[:lower:]')" | |
fi | |
fi | |
spongebob_str="${spongebob_str}$char" | |
charindex=$(( $charindex + 1 )) | |
done | |
echo "${spongebob_str}" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment