Skip to content

Instantly share code, notes, and snippets.

@gmolveau
Created May 23, 2021 21:04
Show Gist options
  • Save gmolveau/92495da69ea36ce8f609ad52dcb32b3e to your computer and use it in GitHub Desktop.
Save gmolveau/92495da69ea36ce8f609ad52dcb32b3e to your computer and use it in GitHub Desktop.
spongebob meme bash function string converter
#!/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